gawk.org 883 B

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:

awk regexp

Our first AWK program

PATTERN { action } PATTERN { action } ... awk regexps are enclodes in slashes. So /this/ is the regexp this. This program searches each line in a file, and if that line matches the regexp /the/, then the second column in

#+BEGIN_SRC awk awk '/the/ { print $2 }' mail-list #+END_SRC

#+RESULTS:

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

#+BEGIN_SRC awk awk '$2 ~ the { print $2 }' mail-list #+END_SRC

#+RESULTS: