find and replace in subdirectory (filename & content - both)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find and replace in subdirectory (filename & content - both)
# 1  
Old 06-25-2008
find and replace in subdirectory (filename & content - both)

Hi,

I have to rename all occurance of CUST_MST to RESELLER_MST both in filename and file content under a directory (say D0) which contains multiple (2-3 levels) sub directory.

Example:

D0 -> D1 -> D2 has a file CUST_MST_TEMP.txt

this contains :

> cat /D0/D1/D2/CUST_MST_TEMP.txt
GRANT REFERENCES ON cust_mst.SRVC_PROVIDER TO srvc_conf_mst;

I would need a script (list of commands) that would rename :

CUST_MST_TEMP.txt to RESELLER_MST_TEMP.txt

and

> cat /D0/D1/D2/RESELLER_MST_TEMP.txt
GRANT REFERENCES ON reseller_mst.SRVC_PROVIDER TO srvc_conf_mst;


the replace is case insensitive.

Thanks in Advance Smilie
# 2  
Old 06-25-2008
Assuming you have only one line in your file:

Code:
awk '{sub("cust_mst","reseller_mst")}' /D0/D1/D2/CUST_MST_TEMP.txt > /D0/D1/D2/RESELLER_MST_TEMP.txt

Regards
# 3  
Old 06-25-2008
no Smilie it's multiline ...
# 4  
Old 06-25-2008
Code:
awk '
/cust_mst.SRVC_PROVIDER/{sub("cust_mst","reseller_mst")}
{print}
' /D0/D1/D2/CUST_MST_TEMP.txt > /D0/D1/D2/RESELLER_MST_TEMP.txt

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compressing & removing files in a directory & subdirectory

Hi, I want a simple line of code that will compress files within a directory specified (parameter) and its subdirectories and also i want to remove files which are exactly 365 days old from the sysdate after this compression. Please help. Thanks, JD (8 Replies)
Discussion started by: Jesshelle David
8 Replies

2. UNIX for Dummies Questions & Answers

Find all files containing string not following symlinks CAT (modified) output content to /filename

This should recursively walk through all dirictories and search for a specified string in all present files, if found output manicured content (eg some regex) with CAT into a specified directory (eg /tmp/) one by one, keeping the original names This is what I have so far, which seems to... (1 Reply)
Discussion started by: lowmaster
1 Replies

3. UNIX for Dummies Questions & Answers

List all File Content its subdirectory

Is there anyway to display the file content in a subdirectory that starts or ends with a certain filename, say .txt? or start with NTS $ ls * dos2unix.bat dos2unix.exe test.txt FilePermissions: filepermission.html NTSLA32_SystemDrive.txt NTSLA36_regedit.txt filepermission.sh ... (1 Reply)
Discussion started by: alvinoo
1 Replies

4. Shell Programming and Scripting

Find: filename in every subdirectory matching a pattern

Hi, I have multiple directories built in following manner /app/red/tmp /app/blue/upd /app/blue/tmp /app/green/tmp /app/red/upd /app/green/upd I have filenames having pattern ONE.XXX.dat TWO.ZZZ.dat and so on across the folders listed above My objective is to list all filenames of a... (4 Replies)
Discussion started by: wahi80
4 Replies

5. UNIX for Dummies Questions & Answers

How to find a file based on pattern & return the filename if found?

Hi all, I am a newbie here. I have this requirement to find a file based on a pattern then return the filename if found. I created a script based on online tutorials. Though, I am stuck & really appreciate if anyone can have a quick look & point me to the right direction? #Script starts... (10 Replies)
Discussion started by: buster_t
10 Replies

6. Shell Programming and Scripting

Search & Replace content of files using gsub in awk

Hi,I have 2 files master.txt & reference.txt as shown below & i require o/p as mentioned in file 3 using awk but content is not replacing properlymaster.txt:... (15 Replies)
Discussion started by: siramitsharma
15 Replies

7. Shell Programming and Scripting

Search & replace content using awk/gsub

Hi, I have two files master.txt & reference.txt. Sample below Master.txt 2372,MTS,AP 919848001104,Airtel,DL 0819,MTS,MUM 919849788001,Airtel,AP 1430,Aircel MP,20 Reference.txt 2372,919848701430,46467 919848002372,2372,47195 2372,919849788001,59027 0819,028803,1 0819,029801,1... (2 Replies)
Discussion started by: siramitsharma
2 Replies

8. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

9. Shell Programming and Scripting

Redirect grep output to dynamique fileName and subdirectory

Hi all i'm new in KSH, i want to write a script to grep a logs files and redirecting the result into a relative subdirectory/file.txt that must be created near to each log file my begin script is : find ./logs -type f -name "*.log" -exec grep error {} \; how i can perform that modest... (10 Replies)
Discussion started by: rambler
10 Replies

10. UNIX for Dummies Questions & Answers

find filename based on file content

:confused: There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who... (4 Replies)
Discussion started by: kollerj
4 Replies
Login or Register to Ask a Question