# Print every input line with more than 4 fields:
NF > 4
# Print every input line in which the last field is more than 4:
$NF > 4
Looks like homework.
What's the difference between 4 and the 4th chicken (or the 4th anything) ?
Run the scripts and see what the difference is.
Read the man page.
Think.
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Ok maybe you can tell me what is the difference between
echo BLA
and
echo $BLA
--
____ __ ___| | ___ Ignorance is .~. hrvoje.spoljar@><.pbf.hr
(_-< '_ \/ _ \ |_/ -_) bliss, but / V \ irc # RoCkY
/__/ .__/\___/__/\___| knowledge is /( )\ icq : 53000945
|_| power! ^-^ http://spole.pbf.hr
Not quite sure what your problem is, but I suppose it's the "dereferencing"
concept.
> # Print every input line with more than 4 fields:
>
> NF > 4
The variable name NF is dereferenced as in most other programming languages.
The value of the (built-in) variable NF is compared against the value 4.
> # Print every input line in which the last field is more than 4:
>
> $NF > 4
You can access the 1st, 2nd, 3rd,... input field by $1 $2 $3 ...
Think of the numbers 1, 2, 3, ... as something like built-in variables.
The $ is the operator to access the fields. You can even use spaces: $ NF
Don't confuse the $ (access fields) in awk with $ (dereference) in shells.
If you specify a name after the $ operator it is considered to be a variable
and dereferenced to obtain the value stored in the variable, then the value
is used to access the field. NF is a built-in variable that carries always
a number. But you may as well use own variables: BEGIN { x = 5 } $x > 0
NF > 4 # deref(NF) > 4
$ NF > 4 # deref(fieldWithNr(deref(NF))) > 4
As in other languages you can ignore the implicit deref operations and focus
on the essential
NF > 4 # NF > 4
$ NF > 4 # fieldWithNr(NF) > 4
NF carries the number of fields, thus may be used to address the last field.
Janis
Now for some real fun:
BLA=PATH
eval echo \$$BLA
So ? guy asked what is the difference betwen NF and $NF
so i thaugth maybe he is familiar with variables and strings
and example i gave would clear up the things... i never said echo was
awk command :-)