Search and replace in the terminal

On Ubuntu it is possible to search and replace a word or phrase with a simple command line

sed -i's/original/new/g' file.txt


sed – Stream EDitor
-i – in-place (save in the original file)


the strings in the order:

s – replacement control
original – regular expression for the word to be replaced.
new – The text to be placed
g – global (Replace all occurrences and not just the first found)
file.txt – file name


Leave a Reply