home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 10.1 Command-line Syntax Chapter 10
The Sed Editor
Next: 10.3 Syntax of Sed Commands

10.2 Conceptual Overview

Sed is a non-interactive, or s tream-oriented, ed itor. It interprets a script and performs the actions in the script. Sed is stream-oriented because, like many UNIX programs, input flows through the program and is directed to standard output. For example, sort is stream-oriented; vi is not. Sed's input typically comes from a file but can be directed from the keyboard. Output goes to the screen by default but can be captured in a file instead.

10.2.1 Typical Uses of Sed Include:

  • Editing one or more files automatically.

  • Simplifying repetitive edits to multiple files.

  • Writing conversion programs.

10.2.2 Sed Operates as Follows:

  • Each line of input is copied into a pattern space.

  • All editing commands in a sed script are applied in order to each line of input.

  • Editing commands are applied to all lines (globally) unless line addressing restricts the lines affected.

  • If a command changes the input, subsequent command-addresses will be applied to the current line in the pattern space, not the original input line.

  • The original input file is unchanged because the editing commands modify a copy of the original input line. The copy is sent to standard output (but can be redirected to a file).

Previous: 10.1 Command-line Syntax UNIX in a Nutshell: System V Edition Next: 10.3 Syntax of Sed Commands
10.1 Command-line Syntax Book Index 10.3 Syntax of Sed Commands

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System