QA
Beginner LevelLinux Commands & SysAdmin

How does awk process space/comma-delimited text columns (print $1, $2)?

❓ Interview Prompt: Explain awk pattern-scanning language, field variables ($1, $2, $0), custom field separators (-F), and line filtering.

'awk' is a powerful pattern-scanning and data processing language that operates on field-delimited columns:

Key Field Variables:

•
'$0': Entire line text.
•
'$1', '$2', '$3': 1st, 2nd, and 3rd delimited fields.
•
'-F","': Specifies custom field separator (e.g. comma for CSV files).
•
'NR': Current row number | 'NF': Number of fields in current row.

Code Implementation Example

bash
# Print 1st (username) and 7th (shell) columns from /etc/passwd using ':' separator
awk -F":" '{print $1, $7}' /etc/passwd

# Filter processes using more than 10% CPU from ps aux output
ps aux | awk '$3 > 10.0 {print $2, $3, $11}'
💡Extracting specific text columns and filtering data using awk.
🎯 Interview Key Takeaway

Use awk -F for field-delimited column extraction and inline condition filtering.

#awk#Text Processing#Columns#Beginner
Back to all Linux Commands & SysAdmin Questions→

More Linux Commands & SysAdmin Interview Questions

Beginner LevelLinux Commands & SysAdmin

How do Linux File Permissions (chmod, chown, chgrp) work in Octal and Symbolic notation?

Beginner LevelLinux Commands & SysAdmin

What is the Linux Filesystem Hierarchy Standard (/bin, /etc, /var, /usr, /opt, /tmp)?

Beginner LevelLinux Commands & SysAdmin

What are File Descriptors (0=stdin, 1=stdout, 2=stderr) and Redirection (>, >>, 2>&1)?