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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access