Find ,replace and overwrite from master and sub dir

Hello experts,

Can someone please help me handling the below situation.

I have files in multiple directories as below.

/data/input/A.txt
/data/input/a1.txt
/data/input/adhoc/b.txt
/data/input/adhoc/b1.txt
/data/input/adhoc/temp/c.txt
/data/input/adhoc/temp/d.txt

where some of the files contain a particular pattern, for example 'replace_me'. (assuming a1.txt b1.txt and d.txt contains that pattern )

I need to identify those files containing 'replace_me' and replace the content with 'You_are_replaced', so that the original files are replaced.

hence
/data/input/a1.txt
/data/input/adhoc/b1.txt
/data/input/adhoc/temp/d.txt files should contain the replaced text.

Can someone please help me out replacing the original file with the new one.

Your help is much appreciated.

Thanks a lot.
pasupuleti

This will affect(recursively) all txt files under /data/input/ that match the pattern

find /data/input -type f -name "*.txt" -exec grep -l replace_me {} \; | xargs sed -i 's/replace_me/You_are_replaced/g'

Thank you kevintse and ctsgnb !