I simply can't figure out how does this line of awk code work.
$$1~/^[^0-9]/ {print $$1;}
I simply can't figure out how does this line of awk code work.
$$1~/^[^0-9]/ {print $$1;}
The $
sign is an operator in awk to reference a field. Example:
$ echo "foo bar car" | awk '{print $2}'
bar
This prints bar
, as bar
is the content of the second field.
A double dollar sign is actually a double reference that will use the information of the first field reference to get to the other field reference. Example:
$ echo "foo bar car 1 2 3" | awk '{print $$5}'
bar
$ echo "foo bar car 1 2 3" | awk '{print $5}'
2
Here it prints bar
as $5
is dereferenced as 2
and thus $$5
is equivalent to $2