The AWK Programming Language, 2nd Edition (Early Release)

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

The goal of this book is to teach you what AWK is and how to use it effectively. AWK was created in 1977 as a simple programming language for writing short programs that manipulate text and numbers with equal ease. It was meant as a scripting language to complement and work well with Unix tools, following the Unix philosophy of having each program do one thing well and be composable with other programs. The computing world today is enormously different from what it was in 1977. Computers are thousands of times faster and have a million times as much memory. Software is different too, with a rich variety of programming languages and computing environments. The Internet has given us more data to process, and it comes from all over the world. We’re no longer limited to the 26 letters of English either; thanks to Unicode, computers process the languages of the world in their native character sets. Even though AWK is nearly 50 years old, and in spite of the great changes in computing, it’s still widely used, a core Unix tool that’s available on any Unix, Linux, or macOS system, and usually on Windows as well. There’s nothing to download, no libraries or packages to import — just use it. It’s an easy language to learn and you can do a lot after only a few minutes of study. AWK is a programming language that makes it possible to handle simple computations with short programs, often only one or two lines long. An AWK program is a sequence of patterns and actions that specify what to look for in the input data and what to do when it’s found. Awk searches a set of files that contain text (but not non-text formats like Word documents, spreadsheets, PDFs and so on) for lines that match any of the patterns; when a matching line is found, the corresponding action is performed. A pattern can select lines by combinations of regular expressions and comparison operations on strings, numbers, fields, variables, and array elements. Actions may perform arbitrary processing on selected lines; the action language looks like C but there are no declarations, and strings and numbers are built-in data types. AWK scans text input files and splits each input line into fields automatically. Because so many things are automatic — input, field splitting, storage management, initialization — Awk programs are usually much shorter than they would be in a more conventional language. Thus one common use of AWK is for the kind of data manipulation suggested above. Programs, a line or two long, are composed at the keyboard, run once, then discarded. In effect, AWK is a general-purpose programmable tool that can replace a host of specialized tools or programs. Perform exploratory data analysis Retrieve, validate, transform, and summarize data-the tasks AWK was originally designed for: Manage small databases, create reports, and write queries Generate text and streamline document preparation Write specialized "little languages" for narrow domains Express, experiment with, and test algorithms For programmers on Unix, Linux, MacOS, and Windows platforms, this updated guide is the most reliable source for learning how to tap into the power of AWK.

Author(s): Alfred V. Aho; Brian W. Kernighan; Peter J. Weinberger
Series: Addison-Wesley Professional Computing Series
Publisher: Addison-Wesley Professional
Year: 2023

Language: English
Pages: 341

Cover Page
Title Page
Contents at a Glance
Contents
Preface
Organization of the Book
The Examples
Evolution of Awk
Acknowledgments
Acknowledgments for the First Edition
1. An Awk Tutorial
1.1 Getting Started
1.2 Simple Output
1.3 Formatted Output
1.4 Selection
1.5 Computing with Awk
1.6 Control-Flow Statements
1.7 Arrays
1.8 Useful One-liners
1.9 What Next?
2. Awk in Action
2.1 Personal Computation
2.2 Selection
2.3 Transformation
2.4 Summarization
2.5 Personal Databases
2.6 A Personal Library
2.7 Summary
3. Exploratory Data Analysis
3.1 The Sinking of the Titanic
3.2 Beer Ratings
3.3 Grouping Data
3.4 Unicode Data
3.5 Basic Graphs and Charts
3.6 Summary
4. Data Processing
4.1 Data Transformation and Reduction
4.2 Data Validation
4.3 Bundle and Unbundle
4.4 Multiline Records
4.5 Summary
5 Reports and Databases
5.1 Generating Reports
5.2 Packaged Queries and Reports
5.3 A Relational Database System
5.4 Summary
6 Processing Words
6.1 Random Text Generation
6.2 Interactive Text-Manipulation
6.3 Text Processing
6.4 Making an Index
6.5 Summary
7 Little Languages
7.1 An Assembler and Interpreter
7.2 A Language for Drawing Graphs
7.3 A Sort Generator
7.4 A Reverse-Polish Calculator
7.5 A Different Approach
7.6 A Recursive-Descent Parser for Arithmetic Expressions
7.7 A Recursive-Descent Parser for a Subset of Awk
7.8 Summary
8 Experiments with Algorithms
8.1 Sorting
8.2 Profiling
8.3 Topological Sorting
8.4 Make: A File Updating Program
8.5 Summary
9 Epilogue
9.1 Awk as a Language
9.2 Performance
9.3 Conclusion
Appendix A: Awk Reference Manual
A.1 Patterns
A.2 Actions
A.3 User-Defined Functions
A.4 Output
A.5 Input
A.6 Interaction with Other Programs
A.7 Summary