sed 多行模式处理字符串;一次替换

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 多行模式处理字符串;一次替换)