problem with awk
Roberto Ragusa
mail at robertoragusa.it
Tue Jun 1 16:32:25 UTC 2010
Adel ESSAFI wrote:
> Hello,
> I have a "little" proble with awk
> here I have a file which contain data like this
>
>
> 101663.dat
> 1 122837.920343696
> 1 121875.899726134
> 1 8011.13164749145
> 1 24955.1102952732
>
>
> when I execute
>
> awk 'BEGIN { }
> echo $2
> END { print "Fin" }
> ' testclean
>
>
> I got this outpout
>
> 1 122837.920343696
> 1 121875.899726134
> 1 8011.13164749145
> 1 24955.1102952732
>
> while I am expecting to get
>
> 122837.920343696
> 121875.899726134
> 8011.13164749145
> 24955.1102952732
>
> without 1 at the beginning of the line. Can you help please.
Try this one:
awk 'BEGIN{} {print $2} END{print "Fin"}'
Without the {}, your $2 was in some way interpreted as a filter (true if $2 not empty).
In fact
awk '$2'
is like
awk '$2{print}'
and prints the entire line if it contains two or more words.
So you line probably means
- evaluate if echo (I suppose this returns false) and do the default action (print the line)
- evaluate if $2 exists (in your case it is true) and do the default action (print the line)
(conclusions based on improvised experimentation)
--
Roberto Ragusa mail at robertoragusa.it
More information about the users
mailing list