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: 9.2 Alphabetical Summary of ex Commands Chapter 10 Next: 10.2 Command-Line Syntax
 

10. The sed Editor

This chapter presents the following topics:

  • Conceptual overview of sed

  • Command-line syntax

  • Syntax of sed commands

  • Group summary of sed commands

  • Alphabetical summary of sed commands

For more information, see sed & awk , listed in the Bibliography.

10.1 Conceptual Overview

sed is a noninteractive, 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 or pipe but can be directed from the keyboard. Output goes to the screen by default but can be captured in a file or sent through a pipe instead.

10.1.1 Typical Uses of sed Include:

  • Editing one or more files automatically.

  • Simplifying repetitive edits to multiple files.

  • Writing conversion programs.

10.1.2 sed Operates as Follows:

  • Each line of input is copied into a "pattern space," an internal buffer where editing operations are performed.

  • 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 commands and address tests are 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 each original input line. The copy is sent to standard output (but can be redirected to a file).

  • sed also maintains the "hold space," a separate buffer that can be used to save data for later retrieval.


Previous: 9.2 Alphabetical Summary of ex Commands UNIX in a Nutshell: System V Edition Next: 10.2 Command-Line Syntax
9.2 Alphabetical Summary of ex Commands Book Index 10.2 Command-Line Syntax

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