Re: problem with awk



On Wed, 2010-06-02 at 13:44 -0500, Dave Ulrick wrote:
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
I don't know that the FS should be declared in the BEGIN processing what
about

awk -F " " '{ print $2}' <file>

--
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



Relevant Pages

  • Re: help with awk
    ... Unspecified is the field separator. ... I didn't check for tabs, ... awk is convenient in that it knows about fields and field separators. ... there are no empty fields. ...
    (comp.lang.fortran)
  • Re: grep -w twice on the same line?
    ... # one match only but in a script, ... echo ... ... not all awk have implemented the set of field separator. ...
    (comp.unix.shell)
  • Re: awk separation of quoted strings
    ... I'm using the following script ... that a blank within a quoted string is interprets by awk ... The easiest thing is to change your field separator to a non-blank that doesn't ...
    (comp.unix.shell)
  • Re: problem with awk
    ... I have a "little" proble with awk ... The field separator is used by 'awk' to divide a line into fields. ... To unsubscribe or change subscription options: ...
    (Fedora)
  • Re: [OT] GAWK question.
    ... ray wrote: ... >> Now mind you this file goes on for ever,and I don't know how long it is. ... > My awk is a little rusty, but with the help of 'man awk' you should be ... change the field separator to ',' and then print the ...
    (comp.os.linux.misc)