Quick replace in textfiles…

Well here is a handy piece of code, that you will definitely need in the future…

Assuming that you have a bunch of text files (like I do) and you want to replace a certain word with another one. Yeah is painful and almost impossible if the number of files is round 5000 :p.

Well they say if you have a terminal, everything is possible… you can’t argue with that!!!

So I had to write a small script that will replace the word “zero” with “0”. Guess what? My beloved Ruby had is own single line way…

ruby -pi -e “gsub(‘zero’, ‘0’)” *.txt

Fascinating right?

Saturday, August 8, 2009   ()