Skip to content
gohacks.dev
Tooling

sed Command Tester

Run a sed script on sample text in your browser: s/// substitutions with groups and flags, deletes, prints, line ranges, y/// and basic or extended regex.

Free · No sign-up · Your inputs stay in your browser

Input

Test a sed command

Output

Output

59 characters

Equivalent command: sed 's/\(DB_HOST\)=.*/\1=10.0.0.5/; /^#/d; s/debug/info/g' file. Without -E, sed uses basic regex: \( \) groups and \{n\} counts, and a bare + or ? is literal in POSIX (GNU sed accepts \+ and \?). In-place editing differs: GNU sed -i, but macOS sed -i '' with an empty suffix.

Runs in this browser. Nothing you paste is sent to a server.

Basic versus extended regex

Without -E, sed uses POSIX basic regular expressions: groups are written with backslashed parentheses and counts with backslashed braces, and + and ? are literal (GNU sed accepts backslashed versions as extensions). With -E they behave as in most other tools. Mixing the two up is the usual reason a substitution does nothing. The GNU sed manual covers both.

In-place editing differs by platform

GNU sed takes sed -i 's/a/b/' file; BSD and macOS sed require a backup suffix argument, empty for none: sed -i '' 's/a/b/' file. Scripts meant for both write a backup suffix such as -i.bak, which both accept.

Share

Frequently asked questions

How do I replace text in a file with sed?
sed -i 's/old/new/g' file on Linux, or sed -i '' 's/old/new/g' file on macOS. Test without -i first to see the output.
Why does my sed group not work?
Without -E, parentheses are literal; write backslashed parentheses for a group in basic regex, or add -E and use plain parentheses.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools