awk积累

1.  计算一个文本中每一列的和

[root@centos ~]# cat aaa.txt 
12 32  2432
132 423 234
12 32 43
23 3 4
12 23 433
[root@centos ~]# awk 'BEGIN{a=0;b=0;c=0}{a+=$1;b+=$2;c+=$3}END{print a;print b;print c;}' <aaa.txt   
191
513
3146

 2.  使用AWK打印指定行

[root@centos ~]# awk 'NR==3' aaa.txt 
12 32 43
[root@centos ~]# awk 'NR<=5 && NR>=3' aaa.txt   
12 32 43
23 3 4
12 23 433

3.  sed打印指定行

[root@MySQL ~]# sed -n '3p' aaa.txt   
12 32 43
[root@centos ~]# sed -n '3,5p' aaa.txt 
12 32 43
23 3 4
12 23 433
原文地址:https://www.cnblogs.com/zx3212/p/9558956.html