String replacement in multiple files (bash)

sed -i 's/old-bit/new-bit/g' *.ext

And hey presto, you’re done. Alternatively, to keep a copy of the old file, perl comes in with a helping hand:

perl -pie 's/old-bit/new-bit/g' inputname > outputname

So replacing a string snippet, like, say, a server IP, in a batch of files, this one liner can do what you need it to do.

But you knew that already 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *