Reputation: 109
I am trying to understand gawk in shell scripting.
How does this command work?
gawk -vN="$N"
and this split based on what
n=patsplit($0,a,/\<\w*\>/,s)
and this
PROCINFO["sorted_in"]="@val_num_desc"
How does it work?
Upvotes: 0
Views: 142
Reputation: 40778
The first command passes an argument to gawk
. The argument is N
and the value assigned to N
is the value of the bash variable $N
.
The second command splits the awk variable $0
into strings based on the regex /\<\w*\>/
. It returns the number of strings that it was able to split. See http://www.gnu.org/software/gawk/manual/gawk.html#String-Functions. The regex is comopsed of \<
(start of word boundary), \w
(word constituent), \>
(end of word boundary). See http://www.gnu.org/software/gawk/manual/gawk.html#GNU-Regexp-Operators
The third command is a special feature of gawk
version 4.1. That is used to traverse arrays in specific order (in a for
loop).. See http://www.gnu.org/software/gawk/manual/gawk.html#Scanning-an-Array
Upvotes: 2