[root@Siegfried test]# awk 'END{print NR}' a 5.打印每行字段数
[root@Siegfried test]# awk -F\\ '{print NF}' a 6.打印最后一行的最后一个字段的值
[root@Siegfried test]# awk 'END{print $NF}' a 7.打印字段数多于4个的行
[root@Siegfried test]# awk '{if(NF>4) print NR}' a 8.打印文件所有字段的总数
[root@Siegfried test]# awk -F\\ 'BEGIN{num=0; sum=0}{num=NF; sum=sum num}END{print sum}' a
9.打印uid在30--40范围内的用户名
[root@Siegfried test]# awk -F: '{if($3>=30&&$3<=40)print $1}' /etc/passwd 10.倒序排列文件的所有字段 #!/bin/awk -f BEGIN{ FS=\" \" }
{
for(i=NF;i>0;i--){
printf(\"%s%s\}
printf(\"\\n\") }
11.打印3-8行
[root@Siegfried test]# awk '{if(NR>=3&&NR<=8)print}' a 12.在文件顶部加上标题“Document”
[root@Siegfried test]# awk 'BEGIN{print \"Document\13.隔行删除
[root@Siegfried test]# awk '{if(NR%2==0) print}' a [root@Siegfried test]# awk '{if(NR%2==1) print}' a 14.每行抽取第一个单词 #!/bin/awk -f BEGIN{ FS=\" \" } { print $1 }
15.打印每行的第一个和第三个单词 #!/bin/awk -f BEGIN{ FS=\" \" } {
print ($1\" \"$3) }
16.打印字段数大于5个的行总数
[root@Siegfried test]# awk -F\\ 'BEGIN{num=0}{if(NF>5)num }END{print num}' a
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- xiaozhentang.com 版权所有 湘ICP备2023022495号-4
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务