|
发表于 2007-10-16 12:26:28
|
显示全部楼层
try this:
假设你要插入的一行文本保存在变量var中:
$ var="a string wants to be added"
你要处理的文件(test.txt)内容如下:- struct in_addr
- hello, world
- this is a pen
复制代码 其中第二行的行首为"一个空格 + 一个tab + 一个空格".
现在你要查找文件中含有"hello"的一行, 在它的后面插入相同缩进的一行内容(已经保存在变量var中), 则使用如下命令即可:
$ sed "/hello/{p; s/\([ \t]*\).*$/\1$var/}" test.txt |
|