A
cd ..
Tools

Awk Text Processing

Pattern scanning and processing with awk for logs and CSVs.

2025-09-04
awk, text-processing, linux

Print specific column

Print 2nd column:

awk '{print $2}' file.txt

Print multiple columns

awk '{print $1, $3}' file.txt

Custom delimiter (CSV)

awk -F',' '{print $1, $3}' data.csv

Print lines matching pattern

awk '/error/ {print}' app.log

Print lines where column matches

Print lines where 3rd column is "FAIL":

awk '$3 == "FAIL" {print}' test_results.txt

Sum a column

Sum all values in column 3:

awk '{sum += $3} END {print sum}' file.txt

Count lines

awk 'END {print NR}' file.txt

Print line numbers

awk '{print NR, $0}' file.txt

Filter by numeric comparison

Print lines where column 2 > 100:

awk '$2 > 100 {print}' file.txt

Calculate average

awk '{sum += $1; count++} END {print sum/count}' file.txt

Print last column

awk '{print $NF}' file.txt

Custom output format

awk '{printf "Name: %s, Score: %d\n", $1, $2}' file.txt

Process log timestamps

Extract hour from timestamp:

awk -F'[: ]' '{print $2}' access.log

Was this useful?

Share with your team

Browse More