How to replace a string in multiple files in multiple folders with different hierarchy in linux command line

I have many files with the extension *.launch distributed in different folders inside the parent directory, the hierarchy is not always the same for the .launch file. i.e: src/folder/sth.launch and src/folder2/../../another.launch, so this solution doesn't work here!

How can I replace a string xarco.py with another string xarcoin all these*launch files in different folders and levels using Linux command? thanks in advance.


Solution 1:

When in the parent directory, you can try with the following command,

find . -type f -name "*.launch" -exec echo sed -i 's/xarco.py/xarco/g' {} \;

and if it 'looks good' remove echo to do the real job,

find . -type f -name "*.launch" -exec sed -i 's/xarco.py/xarco/g' {} \;

If there are problems with permissions, you may need to prefix with sudo:

sudo find ...