This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: script for help
 
Similar Threads
Is it possible to call a action of one war file from action of another war file?
Problem with threads (concurrency)
Sub Folder files copy Problem
Single type import error.
perl String find and replace - count ?