O'Reilly logo

Beginning Unix by Paul Weinstein, Jeremy C. Reed, Craig Zimmerman, Joe Merlino, Paul Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required