Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning AWK Programming

You're reading from   Learning AWK Programming A fast, and simple cutting-edge utility for text-processing on the Unix-like environment

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788391030
Length 416 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Shiwang Kalkhanda Shiwang Kalkhanda
Author Profile Icon Shiwang Kalkhanda
Shiwang Kalkhanda
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with AWK Programming FREE CHAPTER 2. Working with Regular Expressions 3. AWK Variables and Constants 4. Working with Arrays in AWK 5. Printing Output in AWK 6. AWK Expressions 7. AWK Control Flow Statements 8. AWK Functions 9. GNU's Implementation of AWK – GAWK (GNU AWK) 10. Practical Implementation of AWK

Processing arrays using loops

If we have to access all the array elements, we can use a loop that executes once for each element of the array. In other programming languages, where indexes are sequentially numbered, a simple for loop construct is used to access the elements of array. Here, AWK has an associative array, so we use a special type of for loop to go through all the indexes of an array. Its syntax is as follows, followed by a listed explanation of the elements involved:

for (var in array)

body of loop

  • var: This is any variable name, which is set to the index of the corresponding array element.
  • in: This is a keyword.
  • array: This is an array name.
  • body of loop: This is a list of AWK statements that are to be executed. If you want to execute more than one action, it needs to be enclosed within braces. The loop will execute until there is an index element in the array...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image