Sitemap

Member-only story

Text Processing with AWK in Linux/Unix with examples

4 min readJun 19, 2024

--

Press enter or click to view image in full size

awk is a powerful programming language and command-line utility for pattern scanning and processing. It is commonly used for text processing and typically used as a data extraction and reporting tool. This guide will help you understand the basics of awk and demonstrate how to use it effectively on Linux/Unix.

Introduction to awk

awk is named after its creators: Alfred Aho, Peter Weinberger, and Brian Kernighan. It processes text line by line, applying patterns and actions specified by the user.

Basic Syntax

The basic syntax of awk is:

awk 'pattern { action }' file
  • pattern: Specifies the condition to match.
  • action: Specifies what to do when the pattern matches.

You can also use awk inline by providing text through pipes or redirection:

echo "text" | awk 'pattern { action }'

Common Use Cases and Examples

Consider a file data.txt:

John Doe 30 180
Jane Smith 25 165
Alice Johnson 35 170
Bob Brown 28 175
Charlie White 32 160

--

--