• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

script for help

 
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You need a recursive solution?
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic