[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
^ in FS
From: |
Dave B |
Subject: |
^ in FS |
Date: |
Wed, 19 Nov 2008 13:00:06 +0100 |
User-agent: |
Thunderbird 2.0.0.17 (X11/20080929) |
I'm having trouble in understanding the behavior of ^ in FS, although I
don't know whether it can be called "bug". Some examples follow (gawk 3.1.6).
$ echo ' f1 , f2,f3 , f 4 ,f5' | awk -v FS='^ *| *, *'
'{for(i=1;i<=NF;i++)print "-->"$i"<--"}'
--><--
-->f1<--
-->f2<--
-->f3<--
-->f<--
-->4<--
-->f5<--
The above FS matches the spaces at the beginning as expected, but
unexpectedly also matches the spaces between "f" and "4". Other
implementations of awk output
--><--
-->f1<--
-->f2<--
-->f3<--
-->f 4<--
-->f5<--
which makes more sense to me.
But if I change FS to FS='^ +| *, *', then gawk works as expected:
$ echo ' f1 , f2,f3 , f 4 ,f5' | awk -v FS='^ +| *, *'
'{for(i=1;i<=NF;i++)print "-->"$i"<--"}'
--><--
-->f1<--
-->f2<--
-->f3<--
-->f 4<--
-->f5<--
Also note that the issue seems related to ^ only, since using FS=' *$| *,
*', with an input of 'f1 , f2,f3 , f 4 ,f5 ' (spaces at the end)
produces (correctly imho)
-->f1<--
-->f2<--
-->f3<--
-->f 4<--
-->f5<--
--><--
Not sure I completely understand what's going on there.
Thanks for any elucidation.
--
D.