Awk the swiss army knife of the Unix toolkit.

The awk command is very handy when you need to filter the contents of a file, a pipe,or keyboard. It searches each line of input for patterns that you specify and when the pattern is matched, it performs an action. You specify the action and patterns.

The action could be to count the number of times the word youtube appears in a file. There are many action options, it is really up to you to figure out how you can manipulate it.

Here is an example, suppose you have the following text in the file myfile.


awk -F-remove ‘/-remove/ {print $1}’ myfile

-F-remove, is the field separator. In this case the separator is -remove, it separates the text before and after it into separate fields, logically speaking.

-remove, is the pattern to match, it has been defined as a field separator earlier with the -F option. The pattern is enclosed within /.

print $1, prints all text in the first column. The column separator has been defined as the word -remove. The input is from the file myfile.

Here is the result of the awk command.


Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *