Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HP-UX awk weird "feature" - 't' not supported as field separator? 2

Status
Not open for further replies.
Jun 22, 2000
6,317
AU
How weird is this:

Code:
$ for l in a b c d e f g h i j k l m n o p q r s t u v w x y z ; do echo abcdefghijklmnopqrstuvwxyz | awk -F $l '{print $1}' ; done

a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
abcdefghijk
abcdefghijkl
abcdefghijklm
abcdefghijklmn
abcdefghijklmno
abcdefghijklmnop
abcdefghijklmnopq
abcdefghijklmnopqr
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrst
abcdefghijklmnopqrstu
abcdefghijklmnopqrstuv
abcdefghijklmnopqrstuvw
abcdefghijklmnopqrstuvwx
abcdefghijklmnopqrstuvwxy
$

I stumbled upon it yesterday when trying to split the controller number out of some disk devices of the format "c32t3d6".

gawk behaves as expected. I'd be curious to see if anyone can reproduce this on other operating systems... or even explain it!

Annihilannic.
 
I found a Solaris box to try it on and both awk and nawk are affected in the same way, but /usr/xpg4/bin/awk is not.

You can get around it by using a BEGIN { FS="t" } clause, or adding FS=t to the command line after the code... but the fact that the -F option is broken this way (and has been for so many years) I find very surprising!

Annihilannic.
 
From my man page:
man awk said:
awk -F t is a special case that sets the field separator to a tab.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV! I just checked the HP-UX and Solaris man pages and there is no mention of that... %-( What OS did you find that on?

Annihilannic.
 
It's ridiculous. :) If they wanted a shortcut for tabs, why not just add a separate -t option or something rather than breaking an existing one? Anyway, I'm glad that mystery is solved!

Another workaround:

Code:
echo nothing | awk -F '[t]' '{print $1}'

Annihilannic.
 
AIX handles it fine:

Code:
# for l in a b c d e f g h i j k l m n o p q r s t u v w x y z ; do echo abcdefghijklmnopqrstuvwxyz | awk -F $l '{print $1}' ; done               

a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
abcdefghijk
abcdefghijkl
abcdefghijklm
abcdefghijklmn
abcdefghijklmno
abcdefghijklmnop
abcdefghijklmnopq
abcdefghijklmnopqr
abcdefghijklmnopqrs
abcdefghijklmnopqrst
abcdefghijklmnopqrstu
abcdefghijklmnopqrstuv
abcdefghijklmnopqrstuvw
abcdefghijklmnopqrstuvwx
abcdefghijklmnopqrstuvwxy
 
AIX handles it fine
Well, I'd say that the AIX implementation of awk isn't standard ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top