Smart Deals - promotions, discount codes and sales

sed Command Tester

Fast, accurate and free online tester komend sed tool running directly in your browser.

Secure (SSL)
Client-Side Processing
100% Free
Instructions
  • 1
    Enter data
    Enter content, paste text or load a file from disk.
  • 2
    Click the button
    The tool will immediately process your data in the browser.
  • 3
    Get the result
    Copy the finished text or save the file to your device.
function runTool() {
  return "Result ready in 0.1s";
}
191 characters
37 characters

Rate this tool:

Related tools

Other tools you may find useful

sed command tester - online stream editor with

preview sed (stream editor) is a Unix/Linux tool for line-by-line text processing using regular expressions. The tool allows you to test sed commands directly in the browser on test text without access to the terminal.

sed tester online sed commands sed regular expressions stream editor online

sed basics

Syntax: sed 'command' file or echo 'text' | sed 'command'. Main commands: s/pattern/replacement/ (substitute), d (delete line), p (print), q (quit), i (insert before), a (append after). Files: sed -i 's/old/new/g' file.txt (in-place with overwrite). Backup: sed -i.bak 's/old/new/g' file.txt.

Text replacement (s command)

s/pattern/replace/flags. g = global(all occurrences). i = case-insensitive. 2 = second occurrence only. Examples: sed 's/foo/bar/g' (replace all foo with bar). sed 's/^/prefix /' (add a prefix to each line). sed 's/ *$//' (remove trailing spaces). sed 's/[0-9]//g' (remove digits).

Regex in sed

Basic: . (any), * (zero or more), ^ (start), $ (end), [...] (class), [^...] (negation). Extended (sed -E): + (one or more), ? (zero or one), | (alternative), () (groups), {n,m} (quantitative). Back-references: \1, \2 for groups. Example: sed -E 's/(\w+) (\w+)/\2 \1/' (swap the word order).

Line ranges

Line number: sed '2d' (remove line 2). Range: sed '2.5d' (remove lines 2-5). Last: sed '$d' (remove last). Pattern: sed '/pattern/d' (remove lines with pattern). Range pattern: sed '/start/,/end/d' (remove between). Negation: sed '/pattern/!d' (keep only lines with pattern = grep equivalent).

FAQ

How to replace text in multiple files at once?

sed -i 's/old/new/g' *.txt. From backup: sed -i.bak 's/old/new/g' *.txt. Recursively: find . -name "*.php" -exec sed -i 's/old/new/g' {} +. grep + sed: grep -rl "old" . | xargs sed -i 's/old/new/g'. Note: sed -i on macOS requires: sed -i "" 's/old/new/g' (empty backup extension).

How to remove empty sed lines?

sed '/^$/d' file.txt (remove carefully blanks). sed '/^\s*$/d' (blank or whitespace only). Comments: sed '/^#/d' (remove lines with #). Empty + comments: sed -e '/^$/d' -e '/^#/d'. Multiple commands: sed -e cmd1 -e cmd2 or sed 'cmd1;cmd2'.

sed vs awk vs perl for text replacement?

sed: quick, simple, one goal = substitution. awk: columns and calculations. perl -pe: full power of Perl for complex patterns. sed example: sed 's/foo/bar/g'. perl: perl -pe 's/foo/bar/g'. Python: python3 -c "import sys; [print(l.rstrip().replace('foo','bar')) for l in sys.stdin]". For simple replacement: sed is the fastest and easiest.

How to reverse the order of lines in a file?

tac: tac file.txt (reverse cat, GNU). sed: sed -n '1!G;h;$p' file.txt (GNU sed). awk: awk '{ lines[NR]=$0 } END { for(i=NR;i>=1;i--) print lines[i] }' file.txt. Python: print("\n".join(open("file.txt").read().splitlines()[::-1])). Sorting: sort -r (by content, not order).

What are the limitations of sed?

No true multi-line support (built-in): sed processes line by line. Workaround: sed with N command (fetch next line into space). No variables or functions (like awk). Complicated regex: better perl or python. GNU sed vs BSD sed: differences in -E, -i, multiline. For complex transformations: awk or python.

Related tools: AWK command generator, regex tester and bash command generator.

Install Webp.pl Have the tools in your own pocket!