Sunday, August 10, 2014

AWK

1. The AWK Tutorial
http://www.grymoire.com/Unix/Awk.html

2. FS : The input field separator variable
Example Usage :
The following script is used to find the major and the minor version of the release kernel.
-bash-4.1$ uname -r
1.7.17(0.262/5/3)
-bash-4.1$ uname -r | awk ' BEGIN { FS="[ , .]"} {print $1 }'
1
-bash-4.1$ uname -r | awk ' BEGIN { FS="[ , .]"} {print $2 }'
7
-bash-4.1$ uname -r | awk ' BEGIN { FS="[ , .]"} {print $3 }'
17(0
-bash-4.1$ uname -r | awk ' BEGIN { FS="[ , .]"} {print $4 }'
262/5/3)
3. NF - Number of Fields
Be sure to take a look at the example in the tutorial here. Crisp explanation.
http://www.grymoire.com/Unix/Awk.html#uh-17

No comments:

Post a Comment