Chapter 2
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 — 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 you 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 Avenue
Get Linux All-In-One For Dummies, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.