• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

script for help

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You need a recursive solution?
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic