shell脚本,awk数组之如何处理多个文件。
[root@localhost awk]# seq 10|xargs -n 2 > file [root@localhost awk]# seq 10 -1 1|xargs -n 2 > file1 [root@localhost awk]# cat file 1 2 3 4 5 6 7 8 9 10 [root@localhost awk]# cat file1 10 9 8 7 6 5 4 3 2 1 [root@localhost awk]# cat file |awk '{print $1}' 1 3 5 7 9 [root@localhost awk]# cat file1 |awk '{print $2}' 9 7 5 3 1 [root@localhost awk]# cat file |awk '{print $1}'>file3 [root@localhost awk]# cat file1 |awk '{print $2}'>file4 [root@localhost awk]# paste file3 file4 1 9 3 7 5 5 7 3 9 1 [root@localhost awk]# paste file3 file4|tr "\t" " " 1 9 3 7 5 5 7 3 9 1 [root@localhost awk]# paste file3 file4|tr "\t" " ">file5 [root@localhost awk]# cat file5 1 9 3 7 5 5 7 3 9 1 [root@localhost awk]# awk '1' file 1 2 3 4 5 6 7 8 9 10 [root@localhost awk]# awk '1' file1 10 9 8 7 6 5 4 3 2 1 [root@localhost awk]# awk '1' file1 file1 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1 [root@localhost awk]# awk '{print NR}' file file1 1 2 3 4 5 6 7 8 9 10 [root@localhost awk]# awk '{print NR,FNR}' file file1 1 1 2 2 3 3 4 4 5 5 6 1 7 2 8 3 9 4 10 5 [root@localhost awk]# [root@localhost awk]# awk 'NR==FNR{a[NR]=$1}NR!=FNR{print a[FNR],$2}' file file1 1 9 3 7 5 5 7 3 9 1 [root@localhost awk]#