NR与FNR
[root@x112 linshi]# awk '{print NR}' c.txt d.txt 1 2 3 4 5 6 7 8 [root@x112 linshi]# awk '{print FNR}' c.txt d.txt 1 2 3 4 1 2 3 4 [root@x112 linshi]# awk 'NR==FNR{print $0}' c.txt d.txt 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4 [root@x112 linshi]# awk 'NR!=FNR{print $0}' c.txt d.txt 6.6.6.6 7.7.7.7 8.8.8.8 9.9.9.9
RS与OFS
[root@x112 linshi]# awk 'BEGIN{RS="."}{print $0}' c.txt |head 1 1 1 1 2 2 2 2 3 3 [root@x112 linshi]# [root@x112 linshi]# awk -F. 'BEGIN{OFS="------"}NR>3{print $0}{print $1,$2,$4}' c.txt 1------1------1 2------2------2 3------3------3 4.4.4.4 4------4------4
RS指定输入换行符,OFS指定输出字段分隔符;
为者常成,行者常至
Give me five~!