Sed Reference
Common sed commands, substitutions, and flags.
Common sed commands, substitutions, and flags.
sed stream-editor patterns: substitution, in-place edits, deleting and printing lines, inserting and appending, regex groups, multiple commands and address ranges, extended with line deletion by pattern, nth-occurrence replacement, case-insensitive matching, trailing-whitespace removal and alternate delimiters.
| Pattern | Command | Description |
|---|---|---|
| Substitute | sed 's/foo/bar/g' file | Replace all occurrences of foo with bar globally. |
| In-place edit | sed -i 's/foo/bar/g' file | Edit file in place; use -i.bak for backup. |
| Delete lines | sed '3d' file | Delete line 3. Use /pattern/d for pattern match. |
| Print lines | sed -n '5,10p' file | Print lines 5 through 10 only. |
| Insert/append | sed '3i\nNew line' file | Insert text before line 3. |
| Regex group | sed 's/(\d+)/[\1]/g' | Capture digits in parentheses and wrap in brackets. |
| Multiple commands | sed -e 's/a/A/g' -e 's/e/E/g' | Apply multiple substitution commands. |
| Address range | sed '1,5s/old/new/' file | Substitute only in lines 1 through 5. |
| Delete blank lines | sed '/^$/d' file | Remove all empty lines. |
| Print a specific line | sed -n '5p' file | Print only line 5; -n suppresses default output. |
| Print the last line | sed -n '$p' file | The $ address means the last line. |
| Replace the Nth occurrence | sed 's/foo/bar/2' file | Replace only the second occurrence on each line. |
| Case-insensitive substitute | sed 's/foo/bar/Ig' file | GNU sed: the I flag ignores case. |
| Substitute within matching lines | sed '/error/s/foo/bar/g' file | Apply the substitution only on lines containing 'error'. |
| Strip trailing whitespace | sed 's/[ \t]*$//' file | Remove spaces and tabs at the end of each line. |
| Use another delimiter | sed 's|/usr/local|/opt|g' file | Choose a delimiter other than / when the pattern contains slashes. |
The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.
| Section | Field | Type | Example |
|---|---|---|---|
| data | pattern | string | Substitute |
| data | command | string | sed 's/foo/bar/g' file |
| data | description | string | Replace all occurrences of foo with bar globall… |
The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.
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 →