Welcome to Server Circle. It's a friendly site and all levels of experience are welcome. Be aware that we use cookies for your login.
Server Circle - Ask questions about Servers and get answers from experts.
Beta (0.66 sec)
Script to replace characters in several files

I need to change any occurrences of RTG78 in several files at once ?

Thanks !
Asked by:
JimmyC
945 points
 Report Abuse
 Share Page - Category: Shell Scripting - Tags: Script to replace characters in several files
 Enter your response
Please use Pastie.org to paste lengthy code or to fix formatting issues with code
  • Responses in reverse (4)

RPL is a very useful utility to have around:

http://www.laffeycomputer.com/rpl.html

Response by:
lgretton
215 points
For FNAME in FILE_NAMES

do

sed -i 's/RTG78/NEW_STRING/g $FNAME > /tmp/o

mv /tmp/o $FNAME

done

Response by:
jalal
3623 points
With GNU utilities:

find . -type f -exec grep -lZ RTG78 {} + | xargs -r0 sed -i 's/RTG78/something/g'

If there may be binary files, you may want to use perl instead of sed:

find . -type f -exec grep -alZ RTG78 {} + | xargs -r0 perl -pi -e 's/RTG78/something/g'

(or use perl in anycase)

Response by:
s
3383 points
You can use SED command

sed 's/search-string/string-to-change/g' file-name >new file

Response by:
mohamad_kian
1548 points


  • Related Questions
About Us : Contact Us : Etiquette : Terms : CDN Failover : ShorterURL : CDN Fallback : © 2013 Server Circle