IBM developerWorks: Awk by example, Part 2 - Records, loops, and arrays | Linux Today

IBM developerWorks: Awk by example, Part 2 – Records, loops, and arrays

Written By
Web Webster
Web Webster
Jan 14, 2001

[ Thanks to Raj
Singh
for this link. ]

“In this sequel to his previous intro to awk, Daniel Robbins
continues to explore awk, a great language with a strange name.
Daniel will show you how to handle multi-line records, use looping
constructs, and create and use awk arrays. By the end of this
article, you’ll be well versed in a wide range of awk features, and
you’ll be ready to write your own powerful awk scripts.”

“Awk is an excellent tool for reading in and processing
structured data, such as the system’s /etc/passwd file. /etc/passwd
is the UNIX user database, and is a colon-delimited text file,
containing a lot of important information, including all existing
user accounts and user IDs, among other things. In my previous
article, I showed you how awk could easily parse this file. All we
had to do was to set the FS (field separator) variable to “:”.

“By setting the FS variable correctly, awk can be configured to
parse almost any kind of structured data, as long as there is one
record per line. However, just setting FS won’t do us any good if
we want to parse a record that exists over multiple lines. In these
situations, we also need to modify the RS record separator
variable. The RS variable tells awk when the current record ends
and a new record begins.”

Complete
Story

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.