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
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 ','