先看一個例子php
[root@puppet opt]# cat test.txt a b c d e f g [root@puppet opt]# awk 'NR%2==1{next}{print NR,$0}' test.txt 2 b 4 d 6 f
當記錄行號除2等於1的時候就跳過該行,不會運行{print NR,$0},再從新讀取下一行ide
next 的應用code
[root@puppet opt]# cat age.txt gao 20 li 23 zhao 25 liu 19 zhang 28 [root@puppet opt]# awk 'NR%2==1{T=$0;next}{print T,"\t"$0}' age.txt |sed '/^gao/i\NAME AGE' NAME AGE gao 20 li 23 zhao 25 liu 19 zhang 28