Chapter 10. Using sed

Sed is a non-interactive text stream editor for editing a copy of text from a file or from standard input. Standard input can be text entered from the keyboard, a file redirection, a string or a variable, or by a pipe. So what would you use sed for? After all, vi is also a text editor. Well, sed allows you to edit small or large files on the fly; you can supply a series of sed commands to edit or delete and off it goes and does the job. Sed does all the changes in one pass, thus making it efficient and, most importantly to the user, fast.

In this chapter we will cover:

  • extracting fields;

  • matching with regular expressions;

  • comparing fields;

  • adding, appending and substitution; and

  • basic sed one-liners and scripts.

You supply ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.