Search and Replace a string1 with string2 in many files
Hi,
I would like to do something like: #!/bin/tcsh $fil foreach( find . -name * ){ sed(%s/string1/string2/g) } that is, 1. go though a directory structure recursively. 2. replace string1 with string2 in all files How do I do this ? THANKS :-) |
For bash you would do something like
#!/bin/bash for file in `find . -type f` do sed -i 's/string1/string2/g' $file; done |
thanks,
got this scripts working: #!/bin/bash echo "Version 0" rm -f tmp for file in `find . -type f` do echo $file sed 's/asdf/fdsa/g' $file > tmp; rm -f $file cat tmp > $file rm -f tmp done (cannot be very fast, but it works) |
That does pretty much the same thing. You might want to use the -i option for sed which edits the file directly. Since you aren't doing anything with the tmp file anyways. Saves you a few lines.
|
My version of SED doesn't know the "-i" option - thats why I rewrote your script.
Thanks again! |
Update your sed to 4.x ;}
Besides that, if it wasn't for that deletion you could even get away with find -type f -exec sed -i 's/asdf/fdsa/g' {} \; Cheers, Tink |
All times are GMT -5. The time now is 04:05 PM. |