問sed的問題 - Linux

By Kelly
at 2009-08-07T12:46
at 2009-08-07T12:46
Table of Contents
1. 想用sed來改某directory 下的所有檔案
不過不確定 find如何跟 sed使用
例如 說 dir/下 把每個檔名的最後一個字元刪掉
像
find -type f -exec sed '/(.*).$/\1/g' {} \;
之類的
但是發現sed好像不認得back reference \1
而且也不確定怎麼把輸出拿來改檔名
或是說
find -type f -exec mv {} `echo sed 's/???/???/g'`
也不確定怎麼把find的 {} 帶給 ``裡..
用|也是
2. 在某個檔案中有用non-ascii寫的註解
compile都會產生warning 所以想拿掉
我在vim中用 s/[^[:print:]]//g是ok的
但 在command line中
sed -i 's/[^[:print:]]//g' src
結果沒事發生..........
[:print:]這應該是posix 的RE sed應該能認得吧?
還是我sed的用法用錯了????
感謝
--
不過不確定 find如何跟 sed使用
例如 說 dir/下 把每個檔名的最後一個字元刪掉
像
find -type f -exec sed '/(.*).$/\1/g' {} \;
之類的
但是發現sed好像不認得back reference \1
而且也不確定怎麼把輸出拿來改檔名
或是說
find -type f -exec mv {} `echo sed 's/???/???/g'`
也不確定怎麼把find的 {} 帶給 ``裡..
用|也是
2. 在某個檔案中有用non-ascii寫的註解
compile都會產生warning 所以想拿掉
我在vim中用 s/[^[:print:]]//g是ok的
但 在command line中
sed -i 's/[^[:print:]]//g' src
結果沒事發生..........
[:print:]這應該是posix 的RE sed應該能認得吧?
還是我sed的用法用錯了????
感謝
--
Tags:
Linux
All Comments
Related Posts
無線網卡的實作

By Sandy
at 2009-08-07T09:11
at 2009-08-07T09:11
無線網卡的實作

By Hamiltion
at 2009-08-07T03:03
at 2009-08-07T03:03
CENTOS 5.3文字介面下安裝mldonkey 3.0

By Daniel
at 2009-08-07T01:45
at 2009-08-07T01:45
關於VirtualBoX 在Ubuntu上的問題

By Rachel
at 2009-08-06T22:19
at 2009-08-06T22:19
關於VirtualBoX 在Ubuntu上的問題

By Liam
at 2009-08-06T22:09
at 2009-08-06T22:09