sed problem

Hi community,

I have millions of files with [ and ] Character.

Now I try to write an easy script that change those characters in an underscore.

Can some one help me?

Many thx

Best approach would be to use stream line editor (SED)

cat a1.dat|sed 's/[/_/g' > a2.dat
cat a2.dat|sed 's/]/_/g' > a1.dat
 
sed -e 's/\[/_/g' -e 's/\]/_/g' your_file > new_file

it doesn�t help, because the script look into file and make the changes there but I need to change the filename, not the content... but many thanks!

Hey!!!

Check out this,

find . -name "*\[*" -o -name "*\]*" |awk '{s=$0;gsub(/[][]/,"_");print "mv " s " " $0;}'|sh

Cheers!
-R

wow brilliant!!!!! But one think I really need to get fix!

He renamed me all datas wich are call e.g. test[].txt BUT if he need rename this "[ASG] Asklepios S&APw-dpfalzklinik Germersheim" he gives me the following error message:

sh: line 1: APw-dpfalzklinik: command not found
sh: line 1: APw-dpfalzklinik: command not found

you know why?!

best regards!!!!!

Hey,

I think you have white spaces in file name. Isn't it?

Check this out,

find . -name "*\[*" -o -name "*\]*" |awk '{s=$0;gsub(/[][]/,"_");gsub(/[ _]+/,"_");print "mv \"" s "\" \"" $0 "\"";}'|sh

Cheers!
-R