Skip to content

Find and replace text in a file with sed — by cscarney on Ask Ubuntu

intermediateforumCC BY-SA (Stack Exchange; version depends on post date)

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

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

Paraphrased from the source. Menus can differ by version, so check the original for full details.

Read the full thread on askubuntu.com

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

sedtextfind and replace

More in Community Answers (Stack Exchange)