我是新來的正規表達式,並不經常處理它,因此發佈它作爲一個問題。正則表達式替換* .xml
我想更換
blah.xml
haha.xml
到
user/home/blah.xml
user/home/haha.xml
我寧願用SED做到這一點。
乾杯
SK
我是新來的正規表達式,並不經常處理它,因此發佈它作爲一個問題。正則表達式替換* .xml
我想更換
blah.xml
haha.xml
到
user/home/blah.xml
user/home/haha.xml
我寧願用SED做到這一點。
乾杯
SK
您可以使用sed
爲:
$ cat file
foo
blah.xml
haha.xml
bar
$ sed -r 's#([^.]*\.xml)#user/home/\1#g' file
foo
user/home/blah.xml
user/home/haha.xml
bar
要回答在評論你的問題,請嘗試:
$ echo "file is blah.xml" | sed -r 's#(\w+\.xml)#user/home/\1#'
file is user/home/blah.xml
sed 's=\(.*\.xml\)=user/home/\1=g'
sed -e 's#^#user/home/#'
inser ts用戶/ home /在每一行的開頭。
感謝它對我的問題稍作修改。如何將「file is blah.xml」更改爲「file is /user/home/blah.xml」 – Kamath 2011-01-19 12:23:19