example 1:
[Bob@hzling20:~/test]$ cat urfile
hello
hello
hello
hello
hello
[Bob@hzling20:~/test]$ sed -n 's/hello/word/;p;=' urfile | sed 'N;s/\n//'
word1
word2
word3
word4
word5
example2:
[root@localhost local]# sed -e 'N' -e 's/\n/ /' urfile #效果和 sed -e 'N;s/\n/ /' urfile一样
1 2
3 4
5 6
7 8
9
而第二个例子里
我觉得是先读取了1因为N读取了2...将\n变成 所以变成了1 2
example3:
一次替换模式:sed ':a;$!{N;ba};s/2/4/'
本质和把所有的文本作为一行处理;和把所有换行符替换成\n效果一样
本文介绍了SED命令的基础用法及高级技巧,包括如何进行文本替换、使用N命令读取下一行内容并与当前行合并处理等。通过示例展示了SED在处理多行文本时的强大功能。
1800

被折叠的 条评论
为什么被折叠?



