kesto.de Cheatsheets

awk

Filter (exclude) long lines

awk '{ if ( length < 400 ) { print $0 } }' input.txt > short_lines.txt

Get the length of the longest line of a file

awk '{ if ( length > x ) { x = length } } END { print x }' input.txt

Filter lines by value of a field

cat input.txt | awk ' BEGIN { FS = "\t" } ; { if ($2 > 10) { print $2 "\t" $1 } } ' > field_2_greater_10.txt