Score:3

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

il flag

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.

Score:5
jp flag

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 ...
Fabian avatar
cn flag
This, because it allows a "dry-run".
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.