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效果一样
[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 多行替换,多行模式处理字符串;一次替换
- 对一个sed"N;P;D"多行模式处理语句的分析
- linux SHELL下替代sed、ask的常用字符串处理(截取,判断、替换)
- 对一个sed"N;P;D"多行模式处理语句的分析
- sed处理大txt文件(1G) 比如替换某一串字符串,或者删除一行
- Linux 批量字符串替换命令(sed, perl )与vi文本下字符替换命令
- iOS NSString 字符串处理:截取字符串、匹配字符串、分隔字符串、拼接字符串、替换字符串
- 一次替换多个词,批量替换多个字符串(使用不了的解决办法)
- 一次替换多个字符串,批量替换多个字符串
- PHP入门教程之字符串处理技巧总结(转换,过滤,解析,查找,截取,替换等)
- sed处理变量替换
- 001_018 Python 一次完成多个字符串替换
- sed 批量替换字符串
- 【linux学习笔记】sed替换字符串
- shell 字符串处理汇总(查找,替换等等)
- 使用CASE WHEN进行字符串替换处理
- php字符串处理 (据说,strtr 比 str_replace 替换速度快四倍)
- sed替换文件夹下字符串
- USTC机试—字符串处理之模式匹配问题
- sqlParser 处理SQL(增删改查) 替换schema 用于多租户模式下