2011-02-23 39 views

回答

0

使用SED替代命令:

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

試試這個:

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

它將取代不管是括號之間。

輸入:

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

輸出:

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

這可能會爲你工作:

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

它使用"的包圍sed的命令,這有時會導致意外的結果。 使用'的代替是笨拙(比較),但更可預測的:

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

'\''表示單個''\',\''','表示