Linux awk

Linux awk

awk -F ‘:’ ‘{print $1,$3}’ passwd
awk -F ‘:’ ‘{print $1" "$3}’ passwd

NR : 每行的记录号
NF : 字段数量变量
FILEENAME : 正在处理的文件名

awk -F ‘:’ ‘{print “Line:” NR,",Col:" NF,",User:" $1}’ passwd
awk -F ‘:’ ‘{printf(“Line:%s Col:%s User:%s\n”,NR,NF,$1)}’ passwd 输出结果同上
awk -F ‘:’ ‘{if ($3 > 10) print "Line:"NR,"Clo:"NF,“User:”$1}’ passwd 输出用户id大于10的

awk -F ‘:’ ‘$1~/^r./{print $1}’ passwd 对第一个单词进行正则匹配,以r开头的
awk -F ‘:’ '$1!~/^r.
/{print $1}’ passwd 对于上面的取反,找到不是以r开头的

awk -F ‘:’ ‘$3>100{print $1,$3}’ passwd

awk -F ‘:’ ‘BEGIN{print “Line Col User”} {print NR,NF,$1} END{print “------“FILENAME”------”}’ passwd

ll | awk ‘BEGIN{size=0} {size += $5} END{print "size is “size/1024/1024"M”}’ 对文件夹下的size进行累加,显示大小

awk -F ‘:’ ‘BEGIN{count=0} KaTeX parse error: Expected group after '^' at position 5: 1!~/^̲/{count++} END{print "count is "count}’ passwd 主要是对行的有效性进行了正则表达式的判别,排除了空行

awk -F ‘:’ ‘BEGIN{count=0} {if ($3>100) name[count++]=$1} END{for (i=0;i<count;i++) print i,name[i]}’ passwd

netstat -anp|awk ‘$6~/CONNECTED|LISTEN/{sum[$6]++}END{for(i in sum) print i,sum[i]}’ 第六个等于CONNECTED或者LISTEN

上一篇:1401【毕设课设】基于单片机汇编语言抢答器系统设计-汇编


下一篇:装系统分区值设置为整数