Book HomeBook TitleSearch this book

Chapter 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.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.