Skip to main content
InterviewHubPRO
Section Overview
Q23

Question 23 of 50

Part 3: Advanced Text Processing & Production Internals (Senior / Lead)

46%
Bash & Shell Scripting (50 Qs)•Part 3: Advanced Text Processing & Production Internals (Senior / Lead)

What are `awk` fundamentals (Pattern-Action, `$1`, `$2`, `NF`, `NR`)?

senior LevelCode Examplebash-shellAdvanced Text Processing

In Simple Words: awk is a complete programming language designed for processing column-oriented structured text:

  • Line parsing: Splits lines by whitespace (or custom delimiter -F',').
  • $0: Entire line.
  • $1, $2, $3: Column 1, Column 2, Column 3.
  • NF: Number of Fields (columns) in the current line ($NF is the last column!).
  • NR: Number of Records (current line number).
bash
# Print username (col 1) and shell (col 7) from /etc/passwd:
awk -F':' '{ print $1 " -> " $7 }' /etc/passwd