Advanced Unix Commands: Sed and AWK

As you build your skills in the Unix environment, simple commands may not offer all the functions you need. Most programmers rely on advanced Unix commands to work with scripts and programs, no matter what language they are using. In this chapter, you learn more about two powerful commands that can bring a new level of flexibility and ease to your programming and general Unix work:

  • sed: a text editor that works on full streams of text
  • AWK: an output formatting language

The commands sed and awk are somewhat unusual as common Unix commands go. Rather than providing a mechanism to navigate directories or create or delete files, these two commands perform operations primarily on existing text. This text can be the contents of an administrative file, such as /etc/passwd; the output from another command, such as ls; or the contents of an actual text file that you've created with a text editor—perhaps a program or a lengthy text file, such as the chapter of a book.

The sed and awk commands find their roots in the old line editor, ed. Almost nobody uses ed anymore, but it can still be found on most Unix systems. (It's probably on yours! At the very least, code to install ed is probably on your installation disks or included in your installation download.) ed is a command-line program for editing text files, written in the early days of computing. In those days, a terminal screen could not display multiple lines of output, so you could work on only ...

Get Beginning Unix now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.