Home » Infrastructure » Unix » Find and Replace in text files only (Sun Solaris 10)
Find and Replace in text files only [message #413730] Fri, 17 July 2009 06:42 Go to next message
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:-

sed: illegal option -- i

How can I have the file name fed into the sed command and have the files modified and saved inline?

Many Thanks,

Re: Find and Replace in text files only [message #413732 is a reply to message #413730] Fri, 17 July 2009 06:59 Go to previous message
Michel Cadot
Messages: 64611
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This question bears no connection with Oracle.
Please find a more appropriate forum.
The topic is locked.

Previous Topic: Message file sp1.msb not found, Error 6 initializing SQL*Plus
Next Topic: add leading spaces
Goto Forum:

Current Time: Sun Mar 26 21:43:47 CDT 2017

Total time taken to generate the page: 0.08845 seconds