You need a way to keep some of your output and discard the rest.
The following code prints the first word of every line of input:
1 |
$ awk '{print $1}' myinput.file |
Words are delineated by whitespace.
The awk utility reads data from the filename supplied on the command line, or from standard input if no filename is given.
Therefore, you can redirect the input from a file, like this:
1 |
$ awk '{print $1}' < myinput.file |
or even from a pipe, like this:
1 |
$ cat myinput.file | awk '{print $1}' |
The awk program can be used in several different ways.
Its easiest, simplest use is just to print one or more selected fields from its input.
Fields are delineated by whitespace (or specified with the -F option) and are numbered starting at 1.
The field $0 represents the entire line of input. awk is a complete programming language; awk scripts can become extremely complex.
This is only the beginning.