NetBSD-Docs archive

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

awk FS magic

The -F option for awk is more clever than the manual says.  Do we want
the behavior, or is the manual right?  

I noticed a working bug in a little script that led to this suprising

        $ echo foo | awk -F t '{print FS}' | hexdump -C
        00000000  09 0a                                             |..|

If the argument to the -F option is


awk assumes you meant '\t' and sets the FS variable to TAB.  That's not
mentioned in the manual.  Apparently the only way to use the letter 't'
as a field separator is with the regex '[t]'.

I'm sure that's meant to help the clueless, because I found myself
taking advantage of it in my own script

        |  grep -f /etc/whitelist.dat   \
        |  awk -F\t '{print $2}'  \
        |  sed s'/[<>]//g'  \

even though I had no right to expect it to work.  

This appears to be the only specially treated character.  The relevant
function is setfs().  It has a pithy comment inside conditional

static char *
setfs(char *p)
#ifdef notdef
        /* wart: t=>\t */
        if (p[0] == 't' && p[1] == 0)
                return "\t";
        if (p[0] != 0)
                return p;
        return NULL;

I find no support for this "wart" at the open group
Maybe we should just change the Makefile?  


Home | Main Index | Thread Index | Old Index