Friday, February 24, 2017

How to fix a spelling mistake in lots of files

First, is it all version controlled? 
And are any of the files currently in editor buffers? Close if so.

There are two different versions of rename

the perl-rename that I was expecting

$ rename 's/monkey/reproducer/g' *monkey*

and the rename from util-linux 2.28.2 that's actually on my Fedora box

$ rename monkey reproducer *monkey*

need to do this in all affected directories, there's probably something you can do with find if there are lots

and then to change the text in all the files (recursive)

$ grep -rl monkey . | xargs sed -i 's/monkey/reproducer/g' 

finally change it in .bash_history too

sed -i 's/monkey/reproducer/g' ~/.bash_history

note that this will corrupt the history of all the commands you just typed.

No comments:

Post a Comment