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

问题描述:

我有一个巨大的sql_text字符串。我想在整个字符串/文件中替换:1,:2,:3等和:b1,:b2,:b3等等的出现。我试过unix中的字符串替换(awk,sed.tr,cut ...)

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

但它不适用于整个字符串。

+0

什么是你的'特点:B'的东西?它占据整个线路还是什么?试试:'sed -n“s /:\([0-9] \ + \)/:b \ 1/gp”your_file' – HuStmpHrrr 2015-03-13 17:02:10

+1

阅读[sed'手册页](http:// man7。 org/linux/man-pages/man1/sed.1.html)应该是一个好的开始。 – 2015-03-13 17:04:39

+0

@ HuStmpHrrr。 Tnx为你的回复,但它没有工作。我在AIX上的多字符串文件中多次出现(不是关于gnu sed) – 2015-03-13 17:16:26

我会做这在Perl像这样:

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

谢谢安迪!它的工作原理 – 2015-03-13 19:48:16

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

谢谢埃德。它也有效。 – 2015-03-14 10:29:42