Keyword based inline Search and Replace with sed

sed is a nifty utility that allows you to search and replace text in a file using a short 1-liner.

The following command does the following:
1. Searches for the keyword in every line of the input_file
2. In every matching line it looks for search_string
3. It replaces every instance of search_string with replace_string

sed '/keyword/s/search_string/replace_string/g' input_file

Neat!

Reference:
https://unix.stackexchange.com/a/155340

Leave a Reply

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