先给出几个正确运行的例子,最后一个有语法错误,可是我不懂错误的含义,请教诸位
sed version: GNU sed 4.1.5
test文件共6行
$ cat test
1 this is the first line
2 this is the second line
3 this is the third line
i this is the fourth line
1 this is the fifth line
2 this is the sixth line
在每行下append一行‘---’
$ sed 'a\---' test
1 this is the first line
---
2 this is the second line
---
3 this is the third line
---
i this is the fourth line
---
1 this is the fifth line
---
2 this is the sixth line
---
找到含有1的行,移到下一行,将this换为THAT
$ sed '/1/{n;s/this/THAT;}' test
1 this is the first line
2 THAT is the second line
3 this is the third line
i this is the fourth line
1 this is the fifth line
2 THAT is the sixth line
找到含有1的行,跳过,其余的每行下append一行‘---’
$ sed '/1/n;a\---' test
1 this is the first line
2 this is the second line
---
3 this is the third line
---
i this is the fourth line
---
1 this is the fifth line
2 this is the sixth line
---
出语法错误的一行,原目的是在含有1的一行的下一行(这里是含有2的那两行)下append一行‘---’
$ sed '/1/{n;a\---;}' test
sed:-e 表达式 #1,字符 0:未匹配的“{”
请问诸位这一句的错误在哪?正确的语法应该如何实现呢。谢谢。
[问题]sed的append(\a)与next命令(n)问题
-
- 帖子: 29
- 注册时间: 2006-07-16 2:26
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
-
- 帖子: 29
- 注册时间: 2006-07-16 2:26