linux 中 sed N选项将两行合并为一行处理

 

001、

(base) root@PC1:/home/test2# ls
a.txt
(base) root@PC1:/home/test2# cat a.txt
1
2
3
4
5
6
7
8
9
10
(base) root@PC1:/home/test2# cat a.txt | sed 'N; s/\n/\t/'    ## 以两行为单位,将换行符替换为制表符
1       2
3       4
5       6
7       8
9       10

 

002、

(base) root@PC1:/home/test4# ls
a.txt
(base) root@PC1:/home/test4# cat a.txt
1
2
aaa
3
4
5
6aaa
aaa
8
9
10
(base) root@PC1:/home/test4# sed '/aaa/N; s/\n/\t/' a.txt
1
2
aaa     3
4
5
6aaa    aaa
8
9
10

 

posted @ 2022-08-17 01:21  小鲨鱼2018  阅读(729)  评论(0编辑  收藏  举报