Find and replace text in a file with sed — by cscarney on Ask Ubuntu
sed -i 's/old/new/g' file edits a file in place, replacing every match. The answer breaks down each part of the command. Note that -i overwrites the file, so test without it first.
Quick steps
- sed -i 's/original/new/g' file.txt
Paraphrased from the source. Menus can differ by version, so check the original for full details.
Source: Find and replace text in a file with sed by cscarney on Ask Ubuntu. Licence: CC BY-SA (Stack Exchange; version depends on post date).
- Source reviewed
- 2026-11-02
- Link checked
- Not yet
- Tested hands-on
- Not by Oddbyte.Me