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 :slight_smile:

Assuming you have only one line in your file:

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

Regards

no :frowning: it's multiline ...

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