您的位置:首页 > 其它

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

2011-07-12 22:29 323 查看
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效果一样
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: