terminal.cab

All commands

sed

Topic: Text

Program: sed

Edits text line by line with a script.

Package: sed

Usage

sed [OPTION]... SCRIPT [FILE]...

Description

Run the editing SCRIPT on every line of the FILEs (or of the keyboard or pipe) and print the result. Without -e or -f the first argument is the SCRIPT. Commands: s/RE/TEXT/ replaces, d deletes, p prints, a, i and c add or change lines, y changes characters, h, H, g, G and x use the hold space, n and N read the next line, q quits.

Options in the simulator

6 more options of the real program, not in the simulator yet
  • --debug not in the simulator yet

    On a real system sed also shows how it reads the script and runs it line by line.

  • -l, --line-length needs a value not in the simulator yet

    On a real system it sets where the l command wraps long lines.

  • --sandbox not in the simulator yet

    On a real system sed then refuses the e, r and w commands.

  • -u, --unbuffered not in the simulator yet

    On a real system sed then reads and writes in smaller pieces; the result stays the same.

  • -z, --null-data not in the simulator yet

    On a real system a zero byte instead of a newline separates the lines.

  • --version not in the simulator yet

    On a real system it prints the version of the program.

Examples

From the lesson Changing text with sed
cat env.conf
API_HOST=staging.example.com
PATHS=/srv/staging:/opt/staging
DEBUG=true
sed 's/staging/production/' env.conf
API_HOST=production.example.com
PATHS=/srv/production:/opt/staging
DEBUG=true
sed 's/staging/production/g' env.conf
API_HOST=production.example.com
PATHS=/srv/production:/opt/production
DEBUG=true

Try it in the terminal

Where you learn it

Lessons

All commands