Recursively Find and Replace Text in bash
Sometimes a global text and replace does not produce the desired result from an Interactive Development Environment (IDE). If you find yourself in this situation take it to the command line. First off some contrived data:
echo "brown fox jumping over grumpy Colin Kaepernick" > kap.txt
mkdir west
echo "and all the world celebrated as the brown fox returned" > west/world.txt
mkdir -p west/east/north/south
echo "brown and serve sausages will be the grand prize" > west/east/north/south/prize.txt
Now lets use some perl magic changing brown occurrences to blue:
find . -print | xargs perl -pi -e 's/brown/blue/g' *
You will find several errors like this which you can safely ignore:
Can't do inplace edit: ./west is not a regular file, <> line 18242.
Let’s check the handiwork:
cat kap.txt
blue fox jumping over grumpy Colin Kaepernick
cat west/world.txt
and all the world celebrated as the blue fox returned
cat west/east/north/south/prize.txt
blue and serve sausages will be the grand prize
Comment