I want to replace 'localhost' with an actual ip like '1.1.1.1' in every file in a directory including subfolders, plus I want it to log the filenames it changed. I'm having a difficult time doing this, what command should I use?
+1
A:
find /path/to/all/files -type f -exec sed -i 's/localhost/IP/g' {}\;
should work. Or you get an idea of how to make sed work on every file that find finds.
vpit3833
2010-07-02 22:54:31
When I do this I get a "missing argument to 'exec'" error.
pg
2010-07-02 22:57:40
It needs a semicolon at the end, that's what causes the "missing argument" error.
David Zaslavsky
2010-07-02 23:37:27
@David: thank you for the comment. I will proof read my answers. Included the missing semi-colon.
vpit3833
2010-07-03 00:33:35
+2
A:
grep -r --files-with-matches localhost *|tee changed_files|xargs sed -i 's/localhost/1.1.1.1/g'
The files changed will be logged to changed_files
.
Matthew Flaschen
2010-07-02 22:56:35