您好,登錄后才能下訂單哦!
shell分別輸出文件奇數行、偶數行
awk
[root@114 ~]# awk 'NR%2==0' test.log 輸出偶數號
2 warning: libgcc-4.4.7-4.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
4 Installing filesystem-2.4.30-3.el6.x86_64
6 Installing ncurses-base-5.7-3.20090208.el6.x86_64
8 Installing glibc-common-2.12-1.132.el6.x86_64
10 Installing glibc-2.12-1.132.el6.x86_64
[root@114 ~]# awk 'NR%2==1' test.log 輸出奇數行
1 Installing libgcc-4.4.7-4.el6.x86_64
3 Installing setup-2.8.14-20.el6_4.1.noarch
5 Installing basesystem-10.0-4.el6.noarch
7 Installing tzdata-2013g-1.el6.noarch
9 Installing nss-softokn-freebl-3.14.3-9.el6.x86_64
sed
[root@114 ~]# sed -n 'n;p' test.log
2 warning: libgcc-4.4.7-4.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
4 Installing filesystem-2.4.30-3.el6.x86_64
6 Installing ncurses-base-5.7-3.20090208.el6.x86_64
8 Installing glibc-common-2.12-1.132.el6.x86_64
10 Installing glibc-2.12-1.132.el6.x86_64
[root@114 ~]# sed -n 'p;n' test.log
1 Installing libgcc-4.4.7-4.el6.x86_64
3 Installing setup-2.8.14-20.el6_4.1.noarch
5 Installing basesystem-10.0-4.el6.noarch
7 Installing tzdata-2013g-1.el6.noarch
9 Installing nss-softokn-freebl-3.14.3-9.el6.x86_64
[root@114 ~]# sed -n '1~2p' test.log
1 Installing libgcc-4.4.7-4.el6.x86_64
3 Installing setup-2.8.14-20.el6_4.1.noarch
5 Installing basesystem-10.0-4.el6.noarch
7 Installing tzdata-2013g-1.el6.noarch
9 Installing nss-softokn-freebl-3.14.3-9.el6.x86_64
[root@114 ~]# sed -n '2~2p' test.log
2 warning: libgcc-4.4.7-4.el6.x86_64: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
4 Installing filesystem-2.4.30-3.el6.x86_64
6 Installing ncurses-base-5.7-3.20090208.el6.x86_64
8 Installing glibc-common-2.12-1.132.el6.x86_64
10 Installing glibc-2.12-1.132.el6.x86_64
sed '1~2p' 其中1,代表firest line,2,代表間隔step,輸出行=1+2*N,奇數行
sed '2~2p' 輸出行=2+2*N,偶數行
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。