Syntax
Description
Thesed (stream editor) command performs text transformations on input streams. It’s particularly powerful for search-and-replace operations, line deletion, and pattern-based text manipulation.
Nash implements a subset of sed’s functionality, focusing on the most common operations while maintaining full sandbox isolation.
Options
The sed script expression to execute. See supported operations below.
Silent mode. Suppress automatic printing of pattern space. Only print lines explicitly selected with the
p command.Specify the script expression explicitly. Useful when the script starts with a dash.
Supported Operations
Substitution: s/old/new/[flags]
Replace text matching a pattern.
Flags:
g- Global: replace all occurrences in each line (not just the first)p- Print: output lines where substitution occurred (use with-n)
Line deletion: Nd
Delete line number N.
Print line: Np
Print only line number N.
Delete all: d
Delete all lines (results in empty output).
Examples
Basic substitution
Global substitution
g flag, only the first occurrence is replaced:
Delete specific line
Print specific line
Silent mode with substitution
Using different delimiters
Pipeline Examples
Transform log levels
Clean up whitespace
Replace file extensions
.md extension.
Chain transformations
Practical Use Cases
Configuration file updates
Remove sensitive data
Format conversion
Version string updates
Extract and transform
Line numbering cleanup
cat -n.
Advanced Examples
Multiple substitutions in order
Conditional replacement with print
Remove empty lines
Extract specific range
Tips
Substitution is literal: Nash’s sed performs literal string replacement, not regular expressions.
s/a.b/xyz/ replaces the literal text “a.b”, not “a” followed by any character and “b”.Delimiter flexibility
You can use any character as the delimiter:Global flag matters
Silent mode usage
Use-n with p flag to see only modified lines:
