Results 1 to 2 of 2
hi,
I need to change multiple files located in different directories
and i can by using SED:
for f in `find . -type f`; do sed -i 's/old/new/g' $f; done
...
- 05-14-2007 #1Just Joined!
- Join Date
- May 2007
- Posts
- 9
Changing multiple files with SED
hi,
I need to change multiple files located in different directories
and i can by using SED:
for f in `find . -type f`; do sed -i 's/old/new/g' $f; done
However, ALL dates of the files will be changed
even if nothing has been changed inside the file
so i want only the date file renewed when the file has been modified!
how can i adhieve this?
Cheerz
Jolan
- 05-14-2007 #2
well, i'm not sure how to do it in general...
but in your specific case, sed will only modify the file when it finds your "old" expression in the file... so why not use grep first to see if "old" is actually in the file. You could try something like:
Code:for f in `find . -type f`; do grep -q 'old' $f && sed -i 's/old/new/g' $f #will only execute if sed finds what it's looking for done
Avatar from xkcd.com, a hilarious computer related webcomic.


Reply With Quote