Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Replacing text from multiple files at multiple location

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 05-12-2010
rudoraj rudoraj is offline
Registered User
Join Date: Jul 2006
Last Activity: 13 February 2015, 4:04 PM EST
Posts: 68
Thanks: 6
Thanked 0 Times in 0 Posts
Replacing text from multiple files at multiple location


I have many files scattered in all different folders. I want to replace the text within all the files using a single command ( awk, sed...) Is it possible?


find all the files in which there is text "memory" and replace it with "branded_memories".

the files can be at the following locations or diectories.


Sponsored Links
Old Unix and Linux 05-12-2010
anbu23's Unix or Linux Image
anbu23 anbu23 is offline Forum Advisor  
Join Date: Mar 2006
Last Activity: 8 February 2017, 4:04 AM EST
Location: Bangalore,India
Posts: 2,153
Thanks: 21
Thanked 159 Times in 150 Posts

for i in $(find /data/jobs/* -name "*.txt" -print)
awk ' { gsub("memory","branded_memories"); print > FILENAME } ' $i

Sponsored Links
Old Unix and Linux 05-12-2010
curleb curleb is offline Forum Advisor  
Registered User
Join Date: Mar 2008
Last Activity: 27 March 2017, 3:48 PM EDT
Location: Surrounded...
Posts: 383
Thanks: 1
Thanked 29 Times in 28 Posts
Perl will do this in place, if you throw a PIE into the mix:

my_list="fileA.txt fileB.txt $(find /data/jobs -name "*.txt" ) "
for i in ${my_list} 
   perl -pi -e 's/{fr_string}/{to_string}/g' ${i} 2>/dev/null 

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing string in multiple files arulanandsp Shell Programming and Scripting 3 09-11-2009 12:35 AM
[help]Delete or replace text in multiple file and multiple directory dzufauzan Shell Programming and Scripting 16 06-05-2009 11:07 AM
renaming multiple files while replacing string kevin9 Shell Programming and Scripting 2 05-10-2009 06:41 PM
replacing text in specific location zeontman HP-UX 1 07-19-2007 05:46 AM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 02:50 PM

All times are GMT -4. The time now is 08:04 AM.