Chinaunix

标题: 交换行 for sed [打印本页]

作者: 1cpuer    时间: 2017-03-18 10:08
标题: 交换行 for sed
seq 20 | sed '1,10 { H; d}; 15G'
11
12
13
14
15

1
2
3
4
5
6
7
8
9
10
16
17
18
19
20

第6行有一空行

| sed -n '6d'
集合在sed 一行命令怎呢写?



作者: moperyblue    时间: 2017-03-18 10:32

  1. sed '1,10{1h;1!H;d};15G'
复制代码

作者: 1cpuer    时间: 2017-03-19 15:55
回复 1# 1cpuer

# seq 20 | sed '1,10{1h;1!H;d};15G' | nl

http://www.2cto.com/kf/201604/504063.html
PgUpgUp
其中 1!G

同理 1!H

! 在逻辑符 and or not 中是 not 非的意思






欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2