sed

Linux · Text · available in the simulator

What it does

Processes and transforms text using expressions.

Syntax

sed [opciones] 'script' [archivo...]

Options and parameters

  • -e

    Adds a command to the script.

    sed -e 's/a/b/' -e 's/c/d/' f.txt
  • -i

    Edits files in place; supports an optional backup suffix.

    sed -i.bak 's/viejo/nuevo/g' f.txt
  • -n

    Suppresses automatic printing of each line; typically used with the p command.

    sed -n '5,10p' f.txt
  • -E

    Uses extended regular expressions.

  • s///g

    Replaces all occurrences in the line, not just the first.

    sed 's/error/AVISO/g' log.txt

Usage examples

  • sed 's/foo/bar/g' archivo
  • sed -n '1,10p' archivo
  • sed -e 's/a/b/' -e 's/c/d/' f.txt
  • sed -i.bak 's/viejo/nuevo/g' f.txt
  • sed -n '5,10p' f.txt
  • sed 's/error/AVISO/g' log.txt
Practise sed

Related commands