unix中的字符串替换(awk,sed.tr,cut ...)

时间:2015-03-13 16:57:10

标签: unix sed

我有一个巨大的sql_text字符串。我希望在整个字符串/文件中替换:1:2:3的出现,依此类推:b1:b2:b3 , 等等。我试过了

sed -e "s/\(.\)\(.\)/\1b\2/"

但它不适用于WHOLE字符串。

2 个答案:

答案 0 :(得分:1)

我会在Perl中这样做:

perl -pe's/:(\d+)/:b$1/g' foo.sql

答案 1 :(得分:1)

$ echo 'occurences of :1, :2, :3 and so on' | sed 's/:\([[:digit:]]\)/:b\1/g'     
occurences of :b1, :b2, :b3 and so on