Working with Advanced Shell Scripting
IN THIS CHAPTER
Trying out the sed command
Working with the awk and sed commands
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 —
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 ...