linux 中sed命令 n和N的区别

 

001、n

(base) root@PC1:/home/test4# ls
a.txt
(base) root@PC1:/home/test4# cat a.txt
1
2
3
4
5
(base) root@PC1:/home/test4# sed 'n;p' a.txt    ## n的作用是将两行作为一行处理,同时保护第一行;即读取下一行到pattern space,此时,pattern space中有2行内容,但是先读取的那一行不会被取代、覆盖或删除
1
2
2
3
4
4
5

 

002、N

(base) root@PC1:/home/test4# cat a.txt
1
2
3
4
5
(base) root@PC1:/home/test4# sed 'N;p' a.txt   ## N的作用是将两行作为一行处理,但是不保护第一行;, 此时模式空间有两行内容
1
2
1
2
3
4
3
4
5

 

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