sed—streamlined editor

sed [–n] [–e script] [–f sfilename] [filename ...]

sed copies the named filename (standard input default) to the standard output, edited according to a script of command. Does not change the original file.

Example A.38.
1   sed 's/Elizabeth/Lizzy/g' file
2   sed '/Dork/d' file
3   sed -n '15,20p' file

EXPLANATION

  1. Substitute all occurrences of Elizabeth with Lizzy in file and display on the terminal screen.

  2. Remove all lines containing Dork and print the remaining lines on the screen.

  3. Print only lines 15 through 20.

Get UNIX® Shells by Example, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.