Chapter 2

Working with Advanced Shell Scripting


check Trying out the sed command

check Working with the awk and sed commands

check Reading some final notes on shell scripting

The preceding chapter introduced 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 Street

1219:Nate Eichhorn:Sales:219.555.5555:1219 ...

Get Linux All-In-One For Dummies, 6th Edition now with the O’Reilly learning platform.

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