Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 883 Bytes

gawk.org

File metadata and controls

27 lines (21 loc) · 883 Bytes

Gnu Gawk Cheatsheet

Introducion

An AWK program does things to a sequence of data. It can easily be used to certain columns of data in a text file. More generally, awk looks through every line of a file, if that line matches a patters, then awk does some action on it. So an awk program looks like:

PATTERN { action } PATTERN { action } …

awk regexp

awk regexps are enclodes in slashes. So /this/ is the regexp this.

Our first AWK program

This program searches each line in a file, and if that line matches the regexp /the/, then the second column in

awk '/the/ { print $2 }' mail-list

I can also narrow the regexp matching. I can make it not match the whole line, but just an expression of that line

awk '$2 ~ /the/ { print $2 }' mail-list