Skip to content

Instantly share code, notes, and snippets.

@Abhinay1997
Last active January 21, 2020 05:35
Show Gist options
  • Save Abhinay1997/6c8c4d85823903116a34d66f2c9ac86e to your computer and use it in GitHub Desktop.
Save Abhinay1997/6c8c4d85823903116a34d66f2c9ac86e to your computer and use it in GitHub Desktop.
My notes on Awk.

AWK Notes

WK is an interpreted programming language. It is very powerful and specially designed for text processing. Its name is derived from the family names of its authors − Alfred Aho, Peter Weinberger, and Brian Kernighan.

The version of AWK that GNU/Linux distributes is written and maintained by the Free Software Foundation (FSF); it is often referred to as GNU AWK.

This version is also known as GAWK. This is what is available through git bash for windows.

Awk Basics

 awk 'BEGIN{printf "Number of lines with THIS "} /This/ {++cnt} END{print cnt}' test.txt

Command line

#Can be used either directly by typing commands on the shell or by specfiying file containing awk commands (.awk extension).
#Directly
$awk '{print}' marks.txt
#Prints all lines in marks.txt
1) Amit     Physics    80
2) Rahul    Maths      90
3) Shyam    Biology    87
4) Kedar    English    85
5) Hari     History    89
#Alternately
$awk -f commands.awk marks.txt
#Where commands.awk contains only {print}
1) Amit     Physics    80
2) Rahul    Maths      90
3) Shyam    Biology    87
4) Kedar    English    85
5) Hari     History    89
@Abhinay1997
Copy link
Author

Will keep updating hopefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment