Re: problem with awk

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

 



On Tue, 1 Jun 2010, Dave Ulrick wrote:

Looks like a field separator (FS) problem. The field separator is used by 'awk' to divide a line into fields. The default 'awk' field separator is "\t" (tab) but your fields are separated by spaces. Try adding this inside the BEGIN {} block:


FS = " ";


This would give you a script like this:


awk    'BEGIN { FS = " "; }
      echo $2
      END   { print "Fin" }
' testclean

Alternatively, you may specify the field separator as an 'awk' option:

awk -F " " '<your script>' testclean

Oops! I zoomed in on the field separator issue without noticing that the rest of your script isn't quite correct. Here's a one-liner that should solve your stated problem:

awk -F "\t" '{print $2}' <filename>

This command will print the second tab-delimited field of every record of a file.

Dave
--
Dave Ulrick
Email: d-ulrick@xxxxxxxxxxx
-- 
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