Chapter 7. Processing Text with awk
Awk is a programming language that can be used to make your shell scripts more powerful, as well as to write independent scripts completely in awk itself. Awk is typically used to perform text-processing operations on data, either through a shell pipe or through operations on files. It's a convenient and clear language that allows for easy report creation, analysis of data and log files, and the performance of otherwise mundane text-processing tasks. Awk has a relatively easy-to-learn syntax. It is also a utility that has been a standard on Unix systems for years, so is almost certain to be available. If you are a C programmer or have some Perl knowledge, you will find that much of what awk has to offer will be familiar to you. This is not a coincidence, as one of the original authors of awk, Brian Kernighan, was also one of the original creators of the C language. Many programmers would say that Perl owes a lot of its text processing to awk. If programming C scares you, you will find awk to be less daunting, and you will find it easy to accomplish some powerful tasks.
Although there are many complicated awk programs, awk typically isn't used for very long programs but for shorter one-off tasks, such as trimming down the amount of data in a web server's access log to only those entries that you want to count or manipulate, swapping the first two columns in a file, or manipulating comma-separated (CSV) files. This chapter introduces you to the basics ...
Get Beginning Shell Scripting 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.