shell编程系列20--文本处理三剑客之awk常用选项

awk选项总结

选项        解释
-v 参数传递
-f 指定脚本文件
-F 指定分隔符
-V 查看awk的版本号

[root@localhost shell]# awk -v num2="$num1" -v var1="$var" 'BEGIN{print num2,var1}'
hello world # -f 选项 文件中读取表达式
[root@localhost shell]# cat .awk
BEGIN{
str="I hava a tream"
location=index(str,"ea")
print location
}
[root@localhost shell]# awk -f .awk [root@localhost shell]# awk -f .awk
Transaction $ Start,Event ID:
[root@localhost shell]# cat .awk
BEGIN{
str="Transaction 243 Start,Event ID:9002"
count=sub(/[-]+/,"$",str)
print str
} # -F 指定分隔符
[root@localhost shell]# awk -F ":" '{print $7}' passwd
/bin/bash
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/bash
/sbin/nologin
/bin/bash
/sbin/nologin # 显示版本号
[root@localhost shell]# awk -V
GNU Awk 4.0.
Copyright (C) , - Free Software Foundation. This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version of the License, or
(at your option) any later version. This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

shell编程系列20--文本处理三剑客之awk常用选项的更多相关文章

  1. shell编程系列18--文本处理三剑客之awk动作中的条件及if/while/do while/for循环语句

    shell编程系列18--文本处理三剑客之awk动作中的条件及if/while/do while/for循环语句条件语句 if(条件表达式) 动作1 else if(条件表达式) 动作2 else 动 ...

  2. shell编程系列17--文本处理三剑客之awk动作中的表达式用法

    shell编程系列17--文本处理三剑客之awk动作中的表达式用法 awk动作表达式中的算数运算符 awk动作中的表达式用法总结: 运算符 含义 + 加 - 减 * 乘 / 除 % 模 ^或** 乘方 ...

  3. shell编程系列14--文本处理三剑客之awk的概述及常用方法总结

    shell编程系列14--文本处理三剑客之awk的概述及常用方法总结 awk是一个文本处理工具,通常用于处理数据并生成结果报告 awk的命名是它的创始人 Alfred Aho.Peter Weinbe ...

  4. shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计

    shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计 shell中的数组的用法: shell数组中的下标是从0开始的 array=("Allen" & ...

  5. shell编程系列19--文本处理三剑客之awk中的字符串函数

    shell编程系列19--文本处理三剑客之awk中的字符串函数 字符串函数对照表(上) 函数名 解释 函数返回值 length(str) 计算字符串长度 整数长度值 index(str1,str2) ...

  6. shell编程系列16--文本处理三剑客之awk模式匹配的两种方法

    shell编程系列16--文本处理三剑客之awk模式匹配的两种方法 awk的工作模式 第一种模式匹配:RegExp 第二种模式匹配:关系运算匹配 用法格式对照表 语法格式 含义 RegExp 按正则表 ...

  7. shell编程系列15--文本处理三剑客之awk格式化输出printf

    shell编程系列15--文本处理三剑客之awk格式化输出printf printf的格式说明符 格式符 含义 %s 打印字符串 %d 打印十进制数 %f 打印一个浮点数 %x 打印十六进制数 %o ...

  8. shell编程系列11--文本处理三剑客之sed利用sed删除文本中的内容

    shell编程系列11--文本处理三剑客之sed利用sed删除文本中的内容 删除命令对照表 命令 含义 1d 删除第一行内容 ,10d 删除1行到10行的内容 ,+5d 删除10行到16行的内容 /p ...

  9. shell编程系列9--文本处理三剑客之sed概述及常见用法总结

    shell编程系列9--文本处理三剑客之sed概述及常见用法总结 sed的工作模式:对文本的行数据一行行处理,如下图 sed(stream editor),是流编辑器,依据特定的匹配模式,对文本逐行匹 ...

随机推荐

  1. P1402 酒店之王[网络瘤(正解)/匈牙利(错解)]

    题目描述 XX酒店的老板想成为酒店之王,本着这种希望,第一步要将酒店变得人性化.由于很多来住店的旅客有自己喜好的房间色调.阳光等,也有自己所爱的菜,但是该酒店只有p间房间,一天只有固定的q道不同的菜. ...

  2. c++中结构体的使用

    文章链接: 结构体定义: struct Books { ]; ]; ]; int book_id; } book; 访问结构体成员: #include <iostream> #includ ...

  3. IDEA使用入门设置(从入门到放弃)

      激活 1:设置JDK路径 2:设置maven环境 3:设置tomcat 4:设置快捷键与eclipse相同 4.1:设置字体大小 5:创建maven  java 工程并进行编译打包等操作 6:创建 ...

  4. js与jquery中html() text() val()中的区别

    首先html() text() val() 是jquery方法. 1.html()取得内容可以包含标签. 2.text()取得内容为元素文本内容. 3.val()只有value属性的元素才能使用该方法 ...

  5. mysql wait_timeout interactive_timeout 详解

    查看mysql server超时时间: msyql> show global variables like '%timeout%'; 设置mysql server超时时间(以秒为单位): 最小设 ...

  6. 瀑布流(基于Django)

    # 后端 from django.shortcuts import render, HttpResponse from django.http import JsonResponse from app ...

  7. gdb, pdb笔记

    gdb gdb --args yourprogram 常用命令 r(run):从头开始运行 c(continue):继续运行 b(breakpoint) filepath:line or namesp ...

  8. Õ() Big-O-notation

    Õ只是大\(O\)表示法的变种,忽略了对数因子: \[f(n) \in \tilde O(h(n))\] \[=> \exists k : f(n) \in O \!\left( h(n)\lo ...

  9. LightOJ - 1336 - Sigma Function(质数分解)

    链接: https://vjudge.net/problem/LightOJ-1336 题意: Sigma function is an interesting function in Number ...

  10. Yarn节点及作用

    1.yarn中的角色:ResourceManager.NodeManager.ApplicationMaster. ResourceManager:集群计算资源的分配,启动ApplicationMas ...