Section 10.1. Conceptual Overview


10.1. Conceptual Overview

The stream editor, sed, is a non-interactive 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 it can also be taken from the keyboard. Output goes to the screen by default, but it can be captured in a file or sent through a pipe instead. GNU sed can edit files that use multibyte character sets.

10.1.1. Typical Uses of sed

  • Editing one or more files automatically.

  • Simplifying repetitive edits to multiple files.

  • Writing conversion programs.

10.1.2. sed Operation

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 an in-memory 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.



Linux in a Nutshell
Linux in a Nutshell
ISBN: 0596154488
EAN: 2147483647
Year: 2004
Pages: 147

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net