开发者

sed replace string with condition

I have one file contains several lines, each line has the format like

2011-07-10 condition hhh aaa: value bbb
2011-07-10 condition ccc aaa: value bbb
开发者_JAVA百科

I want to use sed to find the value string, which is between "aaa:" and "bbb", and replace to "gotit" based on the condition that the string following condition is ccc. and after sed, this file becomes

  2011-07-10 condition hhh aaa: value bbb
  2011-07-10 condition ccc aaa: gotit bbb


Given my limited knowledge of sed/regex:

sed 's/\(condition ccc.*aaa: \).*\( bbb$\)/\1gotit\2/' file


Heres more logical:

sed '/ccc/{ s/\(.*aaa: \).*\( bbb\)/\1gotit\2/g }' inputfile

sed operates only on the line that contains ccc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜