sed & awk 2nd Ed.

UNIX Power Tools

Dale Dougherty, Arnold Robbins

Publisher: O'Reilly, 1997, 407 pages

ISBN: 1-56592-225-5

Keywords: Programming

Last modified: April 10, 2022, 2:36 p.m.

sed and awk are tools used by users, programmers, and administrators. sed, so called because it is a stream editor, is perfect for applying a series of edits to a number of files. awk, named after its develoipers, Aho, Weinberger, and Kernighan, is a programming language that lets you manipulate structured data easily and generate formatted reports. This second edition covers awk as described by the POSIX standard, as well as a number of both freely available and commercial versions of awk.

The book begins with an overview and a tutorial that demonstrate a progression in functionality from grep to sed to awk. sed and awk share a similar command-line syntax, accepting user instructions in the form of a script. Because all three programs use UNIX regular expressions, an entire chapter is devoted to understanding UNIX regular expression syntax.

Next, the book describes how to write sed scripts. After getting started by writing a few simple scripts. you'll learn other basic commands that parallel manual editing actions, as well as advanced commands that introduce simple programming constructs. Among the advanced commands are those that manipulate the hold space, a set-aside temporary buffer.

The second part of the book has been extensively revised to include POSIX awk as well as coverage of three freely available and three commercial versions of awk. The book introduces the primary features of the awk language and how to write simple scripts. You'll also learn:

  • Common programming constructs
  • How to use awk's built-in functions
  • How to write user-defined functions
  • Debugging techniques for awk programs
  • How to develop an application that processes an index, demonstrating much of the power of awk
  • FTP and contact information for obtaining various versions of awk

Also included is a miscellany of user-contributed scripts that demonstrate a wide range of sed and awk scripting styles and techniques-

  1. Power Tools for Editing
    • May You Solve Interesting Problems
    • A Stream Editor
    • A Pattern-Matching Programming Language
    • Four Hurdles to Mastering Sed and Awk
  2. Understanding Basic Operations
    • Awk, by Sed and Grep, out of Ed
    • Command-Line Syntax
    • Using sed
    • Using awk
    • Using sed and awk Together
  3. Understanding Regular Expression Syntax
    • That's an Expression
    • A Line-Up of Characters
    • I Never Metacharacter I Didn't Like
  4. Writing sed Scripts
    • Applying Commands in a Script
    • A Global Perspective on Addressing
    • Testing and Saving Output
    • Four Types of Sed Scripts
    • Getting to the PromiSed Land
  5. Basic sed Commands
    • About the Syntax of Sed Commands
    • Comment
    • Substitution
    • Delete
    • Append, Insert and Change
    • List
    • Transform
    • Print
    • Print Line Number
    • Next
    • Reading and Writing Files
    • Quit
  6. Advanced sed Commands
    • Multi-line Pattern Space
    • A Case for Study
    • Hold That Line
    • Advanced Flow Control Commands
    • To Join a Phrase
  7. Writing Scripts for awk
    • Playing the Game
    • Hello, World
    • Awk's Programming Model
    • Pattern Matching
    • Records and Fields
    • Expressions
    • System Variables
    • Relational and Boolean Operators
    • Formatted Printing
    • Passing Parameters into a Script
    • Information Retrieved
  8. Conditionals, Loops, and Arrays
    • Conditional Statements
    • Looping
    • Other Statements That Affect Flow Control
    • Arrays
    • An Acronym Processor
    • System Variables That Are Arrays (Nawk)
  9. Functions
    • Arithmetic Functions
    • String Functions
    • Writing Your Own Functions (nawk)
  10. The Bottom Drawer
    • The getline Function
    • The close() Function
    • The system() Function
    • A Menu-Based Command Generator
    • Directing Output to Files and Pipes
    • Generating Columnar Reports
    • Debugging
    • Limitations
    • Invoking Awk Using the #! Syntax
  11. A Flock of awks
    • Original awk
    • Freely available awks
    • Commercial awks
    • Epilogue
  12. Full-Featured Applications
    • An interactive Spell Checker
    • Generating a Formatted Index
    • Spare Details of the masterindex Program
  13. A Miscellany of Scripts
    • uutot.awk — Report UUCP Statistics
    • phonebill — Track Phone Usage
    • combine — Extract Multipart uuencoded Binaries
    • mailavg — Check Size of Mailboxes
    • adj — Adjust Lines for Text Files
    • readsource — Format Program Source Files for troff
    • gent — Get a termcap Entry
    • plpr — lpr Preprocessor
    • transpose — Performa a Matrix Transposition
    • m1 — Simple Macro Processor
  1. Quick Reference for sed
  2. Quick Reference for awk
  3. Supplement for Chapter 12

Reviews

sed & awk

Reviewed by Roland Buresund

Good ******* (7 out of 10)

Last modified: April 10, 2022, 2:37 p.m.

A very good book, was updated. Still good.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required