How does awk work for text processing?

Answer

awk is a pattern-scanning and processing language. It reads input line by line, splits each line into fields ($1, $2, ...; $0 = whole line) using whitespace or a custom delimiter (-F: for colon), and applies rules of the form pattern { action }. Examples: awk '{print $2}' file prints the second field of every line. awk -F: '{print $1}' /etc/passwd prints all usernames. awk '$3 > 100 {print $1, $3}' data filters and formats. awk 'BEGIN{sum=0} {sum+=$1} END{print sum}' numbers sums a column. awk is the tool of choice for structured tabular data processing in shell pipelines, far more powerful than basic cut or grep.