Sed Reference

Common sed commands, substitutions, and flags.

The data

0

Pattern
Substitute
Command
sed 's/foo/bar/g' file
Description
Replace all occurrences of foo with bar globally.

1

Pattern
In-place edit
Command
sed -i 's/foo/bar/g' file
Description
Edit file in place; use -i.bak for backup.

2

Pattern
Delete lines
Command
sed '3d' file
Description
Delete line 3. Use /pattern/d for pattern match.

3

Pattern
Print lines
Command
sed -n '5,10p' file
Description
Print lines 5 through 10 only.

4

Pattern
Insert/append
Command
sed '3i\nNew line' file
Description
Insert text before line 3.

5

Pattern
Regex group
Command
sed 's/(\d+)/[\1]/g'
Description
Capture digits in parentheses and wrap in brackets.

6

Pattern
Multiple commands
Command
sed -e 's/a/A/g' -e 's/e/E/g'
Description
Apply multiple substitution commands.

7

Pattern
Address range
Command
sed '1,5s/old/new/' file
Description
Substitute only in lines 1 through 5.

Fetch the same bytes

The static files are identical to what the API returns, but with no rate limit and no server round trip. Use the API when you want a query and a content type; use the files when you want to cache one document.

curl "https://yjtoon.com/api/dataset/sed-reference?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/sed-reference.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • unix
  • sed
  • text-processing
  • stream-editor