Chapter 2

Advanced Shell Scripting

In This Chapter

arrow Trying out the sed command

arrow Working with the awk and sed commands

arrow Reading some final notes on shell scripting

The preceding chapter introduces you to some of the power available through shell scripting. All the scripts in that chapter are simple bash routines that allow you to run commands and repeat operations a number of times.

This chapter builds upon that knowledge by showing how to incorporate two powerful tools — sed and awk — into your scripts. These two utilities move your scripts to the place where the only limit to what you can do becomes your ability to figure out how to ask for the output you need. Although sed is the stream editor and awk is a quick programming language, they complement each other so well that it’s not uncommon to use one with the other. The best way to show how these tools work is to walk through some examples.

Trying Out sed

The following are sample lines of a colon-delimited employee database that has five fields: unique id number, name, department, phone number, and address.

  1218:Kris Cottrell:Marketing:219.555.5555:123 Main Street1219:Nate Eichhorn:Sales:219.555.5555:1219 Locust Avenue1220:Joe ...

Get Linux All-in-One For Dummies, 5th Edition now with O’Reilly online learning.

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