|
发表于 2008-1-16 10:48:39
|
显示全部楼层
那只要将符合要求的行直接替换即可:- $ sed '/#define[ \t][ \t]*ABC[ \t]/s/^.*$/#define ABC 2/' file1 > file2
复制代码
以上表达式基本等价于:- $ sed 's/#define[ \t][ \t]*ABC[ \t].*$/#define ABC 2/' file1 > file2
复制代码
PS:
提问时尽量将要求写清楚一点,因为不同的命令都会有它的局限之处,所以需求越精确越好。
比如上面的表达式作用于如下行
printf("#define ABC %s\n", "hello");
第一个命令会得到:
#define ABC 2
第二个命令则得到:
printf("#define ABC 2 |
|