Re: problem with awk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2010-06-02 at 13:41 -0500, Dave Ulrick wrote: 
> On Tue, 1 Jun 2010, Aaron Konstam wrote:
> 
> > On Tue, 2010-06-01 at 17:08 +0100, 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.
> >>
> > gawk '{print $2}' <filename>
> > will do what  you want.
> 
> If he's using spaces rather than tabs to delimit the fields, an additional 
> (g)awk option will be needed:
> 
> gawk -F "\t" '{print $2}' <filename>
Now I am confused.The awk (or gawk)line I gave will do what he wants if
he uses spaces. Your change causes tab to be the separator looked for
which is not what he said he wants.

The BEGIN and END feature in awk is for doing special things outside the
awk loop like producing headers and trailers which are not needed here.

--
=======================================================================
The absurd is the essential concept and the first truth. -- A. Camus
=======================================================================
Aaron Konstam telephone: (210) 656-0355 e-mail: akonstam@xxxxxxxxxxxxx

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux