Print lines between two patterns

Range pattern: include lines from START to END inclusive

awk '/START/,/END/' file.txt

tool
awk15 commands
tags
awklinux

More awk commands

  • awk 'NR>1 {print $1, $2}' data.csv

    Process all lines except the first (header)

  • awk '{count[$1]++} END {for (k in count) print count[k], k}' access.log | sort -rn

    Frequency count of the first field (e.g. IP addresses)

  • awk '{print $NF}' file.txt

    NF holds the number of fields; $NF is the last field

  • awk '$2 > 500 && $5 == "POST"' access.log

    Print lines where field 2 > 500 AND field 5 is POST

  • awk '{printf "%-20s %5d\n", $1, $2}' data.txt

    Aligned printf formatting with fixed column widths

all 15 awk commands