UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 9.2 Alphabetical Summary of ex CommandsChapter 10Next: 10.2 Command-Line Syntax
 

10. The sed Editor

Contents:
Conceptual Overview
Command-Line Syntax
Syntax of sed Commands
Group Summary of sed Commands
Alphabetical Summary of sed Commands

This chapter presents the following topics:

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

10.1 Conceptual Overview

sed is a noninteractive, or stream-oriented, editor. 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 CommandsUNIX in a Nutshell: System V EditionNext: 10.2 Command-Line Syntax
9.2 Alphabetical Summary of ex CommandsBook Index10.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