开发者

How do i change the following input line using SED?

How do i change the following 开发者_如何学运维input line using SED ?

Input - bus_ln in ('abc');

Required O/P - bus_ln in ('def','xyz');


Give this a try:

sed "s/\([^(]*\)('[^']*')/\1('def','xyz')/" inputfile

It will replace whatever is between the parentheses.

Input:

bus_ln in ('abc');
foo('bar');
baz aaa bbb ('ccc ddd') some more text

Output:

bus_ln in ('def','xyz');
foo('def','xyz');
baz aaa bbb ('def','xyz') some more text


Using sed substitute command:

echo "bus_ln in ('abc');" | sed "s/bus_ln in ('abc');/bus_ln in ('def','xyz');/"


$ echo "Input - bus_ln in ('abc');" | ruby -e 'print gets.gsub(/(.*\()(.[^;]*)(\);)/,"\\1\047def\047,\047xyz\047\\3")'
Input - bus_ln in ('def','xyz');


This might work for you:

echo "bus_ln in ('abc');" | sed "s/'.*'/'def','xyz'/"
bus_ln in ('def','xyz');

This uses "'s to surround the sed commands which may sometimes lead to unexpected results. Using ''s instead is clumsy (in comparison) but more predictable:

echo "bus_ln in ('abc');" | sed 's/'\''.*'\''/'\''def'\',\''xyz'\''/'
bus_ln in ('def','xyz');

Where '\'' represents a single ' and '\',\'' represents ','

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜