Gawk is, essentially, a tool to process text data. It can work out like simple commands such as cat or grep as well as create powerful scripts and data filters. The Gawk instruction generally consists of a pattern and and action. It can operate on text files as well as standard input. A gawk command will look like:
Example 1, to look for name "aditya" in contacts files, you can run:
Here Gawk will look for the pattern "aditya" and if it is found it will print it, as specified in action.
Example 2, to check out the products for which you have to pay some amount and .99 bucks like 9.99 or something, you can do:
- length(str): returns the number of characters in the string.
- index(str1, str2): returns the position in str2 where str1 begins.
- split(str, arr, delim): copies the segment of str that are separated by delimiter into array and returns the number of elements.
- substr(str, pos, len): returns a substring starting at pos of lenght len
- match(str, pattern): returns the position of the match.
- sub(pattern, replacement, str) and gsub(pattern, replacement, str): performs a substitution on string str replacing every pattern with replacement string. gsub is global sub.
- toupper(str) and tolower(str): obvious.