Linux Find and Replace with sed

Have you ever found yourself googling how to find and replace within a file from the linux command line? Me too. Here’s the answer that works for me: sed -i 's/search/replace/g' /path/to/file.txt

Rather than type that command all the time, I wrote a bash script to simplify things. BE WARNED! I know very little about bash scripting or the sed command, so this script probably only works for simple search and replace strings. I bet it would break if either string contained quotes or other reserved characters. That being said, it works like a charm for simple stuff. I named it esed (for easy sed).

Usage: esed search replace /path/to/file.txt

It’ll ask you to confirm the replace, then after a successful run it’ll show the contents of the file. I’ve found that useful for small files, but not so useful for big ones. You could always comment that line out if it annoys you.   :)

[note color=”#DDD”]Download
[/note]
Category(s): Googling for Answers, Linux
Tags:

Leave a Reply

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

* Copy this password:

* Type or paste password here: