Skip to content

Replace text from terminal

Mert Buran edited this page Apr 17, 2020 · 1 revision

sed is probably the go-to tool for replacing text in files from terminal.

I know the syntax, that's easy...

sed "s/old_text/new_text/g" old_file.txt > new_file.txt

and to change it in-place...

sed -i "s/old_text/new_text/g" file.txt

...why doesn't that work? 🤔

Oh I should've added an empty string "" after -i!

sed -i "" "s/old_text/new_text/g" file.txt