Find and Replace in text files only [message #413730] |
Fri, 17 July 2009 06:42 |
graham009
Messages: 1 Registered: July 2009 Location: England
|
Junior Member |
|
|
I want to replace text in all TEXT (not binary) files in the directory (including sub-directories).
I am new to scripting in Unix (I just started using a Sun Solaris 10 platform which seems to limit what you can use from the Web).
I need help to combine the following find and sed commands and perhaps an explanation of how the 'piping' of data from one command feeds into the other work. Again you can find examples and some notes on how they work, but unsure how to save the original files with the changes made.
I would like to use sed for the substation, but I have to use find to determine what files I want to use.
find . -exec grep n "oldText" '{}' \; -print
This nearly works for the current directory only, but the files are not modified!
find . -type f -name '*.read' -print -exec sed s/oldText/newText/g '{}' \;
If I include the -i option with sed I get the error:-
How can I have the file name fed into the sed command and have the files modified and saved inline?
Many Thanks,
Graham.
|
|
|
|