Text Processing

sed

Edits text streams with scripted rules.

sed is a stream editor commonly used for substitution, deletion, and simple line-based transformations.

Syntax
sed [options] script [file...]

Arguments explained

  • script describes the edit, such as s/old/new/.
  • -n suppresses automatic printing.
  • -i edits files in place on many sed versions.

Common examples

Replace text in output
sed 's/error/ERROR/g' app.log

Prints app.log with replacements, without changing the file.

Print a line range
sed -n '10,20p' file.txt

Prints lines 10 through 20.

sed Command
FieldDetails
Commandsed
CategoryText Processing
Primary useEdits text streams with scripted rules.
Syntaxsed [options] script [file...]