wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes script for help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "script for help" Watch "script for help" New topic
Author

script for help

Jackie Wang
Ranch Hand

Joined: Apr 18, 2002
Posts: 315
I want to change all the text files in one directory which contains the string "John" to "Peter" using some unix script. (because there are >100 and i can't vi every file and change it)
sample1.txt
John 10
Mary 20
Mat 50
sample2.txt
John 10
Jeff 40
Mat 50
to
sample1.txt
Peter 10
Mary 20
Mat 50
sample2.txt
Peter 10
Jeff 40
Mat 50
in my unix directory. Are there a way to do it?
Thanks so much for the script.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923


You need a recursive solution?


http://home.arcor.de/hirnstrom/bewerbung
Jackie Wang
Ranch Hand

Joined: Apr 18, 2002
Posts: 315
hi Stef,
Thanks so much for the code. I think I don't need it for now. =)
Because it's all in one flatten directory
Sorry that I was new to the UNIX, so should i create a script in the same directory and call it something like mytest.sh ?
Jackie Wang
Ranch Hand

Joined: Apr 18, 2002
Posts: 315
hi Stef,
I put that into script.sh
chmod and ran it by ./script.sh

Any clue that why am having this error?
FILES=`grep -l John *`: Ambiguous
FILES: Undefined variable
thanks!
 
wood burning stoves
 
subject: script for help