Replacing text from multiple files at multiple location


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing text from multiple files at multiple location
# 1  
Old 05-12-2010
Replacing text from multiple files at multiple location

Hi,

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?

example

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.


/data/jobs/temp/subject.txt
/data/jobs/temp/control/SSC/something.txt
/data/jobs/temp20/subject.txt
/data/jobs/temp21/SRE/touch.txt

Thanks,
# 2  
Old 05-12-2010
Code:
for i in $(find /data/jobs/* -name "*.txt" -print)
do
awk ' { gsub("memory","branded_memories"); print > FILENAME } ' $i
done

# 3  
Old 05-12-2010
Perl will do this in place, if you throw a PIE into the mix:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with search and replacing multiple items in multiple files

Im having an issue when trying to replace the first column with a new set of values in multiple files. The results from the following code only replaces the files with the last set of values in val.txt. I want to replace all the files with all the values. for date in {1..31} do for val in... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

2. UNIX for Beginners Questions & Answers

Copy data at specified location from multiple files

Hello everyone, Im super new to coding but increasingly in need of it at work. Im have task stacked because of this problems, that I cannot figure out how to solve looking on the internet after trying many many things that looked similar to me. I have multiple data files of the form (see below).... (2 Replies)
Discussion started by: Xfiles_fan
2 Replies

3. Shell Programming and Scripting

Copying the files in to multiple location using shell script

Hi All, i'm trying to copy the 1.txt files (sample files) in to different path location using the below command. But it is not copying the files , when i tried for single location able to copy the file. can any one please assist here. Please find the below path :- /ckr_mkr1/licencekey... (2 Replies)
Discussion started by: venkat918
2 Replies

4. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

I have 4000 files like $cat clus_grp_seq10_g.phy 18 1002 anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG aver_OOF92921_1 ... (1 Reply)
Discussion started by: sammy777888
1 Replies

5. Shell Programming and Scripting

Replacing matched patterns in multiple files with awk

Hello all, I have since given up trying to figure this out and used sed instead, but I am trying to understand awk and was wondering how someone might do this in awk. I am trying to match on the first field of a specific file with the first field on multiple files, and append the second field... (2 Replies)
Discussion started by: karlmalowned
2 Replies

6. Shell Programming and Scripting

Replacing old TNS entries with New one in multiple files

I have requirement to replace old TNS entries with New one in multiple files. one file may contain more then one occurrence of tns. Example: Below is the one of occurrence in a current file(s). i am interested to replace only red part. <connection-pool name="Google_APP_CP"... (4 Replies)
Discussion started by: KDDubai333
4 Replies

7. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

8. Shell Programming and Scripting

Replacing string in multiple files

Hi, I need to replace the string 'abcd' with 'xyz' in a file sample.xml This sample.xml is also present in the subdirectories of the current directory. Eg, If I am in /user/home/ the sample.xml if present in /user/home/ /user/home/folder1/ /user/home/folder2/... (3 Replies)
Discussion started by: arulanandsp
3 Replies

9. Shell Programming and Scripting

renaming multiple files while replacing string

hi, i've found a few examples of scripts to do this but for some reason can't get them to work properly. basically i have some dirs with a few hundred files mixed in with a bunch of other files that were made with a typo in part of them. long-file-names-tyo-example.ext want to be able... (2 Replies)
Discussion started by: kevin9
2 Replies

10. HP-UX

replacing text in specific location

i have a file that looks like this: 000000112/01/2008 D99999 000000 12/01/2008 D99999 000000 12/01/2008 1D99999 i need to replace the blanks into 1 for column 7,18-19 how can this be achieved using awk? Thanks. (1 Reply)
Discussion started by: zeontman
1 Replies
Login or Register to Ask a Question