3

I have a csv file with the format :

"a b c","d","e","f",
"bla","bla","bli","fff"

The FPAT as given here by the official GNU site stipulate that "Assigning a value to FPAT overrides field splitting with FS and with FIELDWIDTHS." However, I have tried their code :

BEGIN {
    FPAT = "([^,]+)|(\"[^\"]+\")"
}

{
    print "NF = ", NF
    for (i = 1; i <= NF; i++) {
    printf("$%d = <%s>\n", i, $i)
    }
}

with this :

echo 'Robbins,Arnold,"1234 A Pretty Street, NE",MyTown,MyState,12345-6789,USA' | gawk -f bin/test.awk

and here is the not expected result :

NF =  5
$1 = <Robbins,Arnold,"1234>
$2 = <A>
$3 = <Pretty>
$4 = <Street,>
$5 = <NE",MyTown,MyState,12345-6789,USA>

I think the default FS (space) was not overriden. Any idea please ?

Hicham
  • 81
  • 6
  • 6
    `FPAT` requires gawk version 4. What do you get from `gawk --version`? – jas Nov 04 '16 at 11:11
  • 2
    GNU Awk 3.1.7. So that's the reason! Thank you @jas – Hicham Nov 04 '16 at 15:14
  • 1
    Here is the features history of gawk for those interested : https://www.gnu.org/software/gawk/manual/html_node/Feature-History.html – Hicham Nov 04 '16 at 15:25
  • On the bright side, with 3.1.7 you still have support for Atari :-) – jas Nov 04 '16 at 15:29
  • :-) . I hate theses limitations when you're not working on your own environment. You have to work around it while the solution is on 1 line of code in the next updates!. – Hicham Nov 04 '16 at 15:44
  • Thanks for this comment stream. All the other pages I found on this topic talked about FPAT as if it was in all versions of awk. Once I knew this was a gawk-specific feature, well, THAT was an easy fix. – baudot May 04 '17 at 17:53
  • 1
    What was the work around with 3.1.7?? – Sam T Aug 09 '19 at 12:22
  • Sorry Sam, I read your comment late. It was a specific bash dev. I quit the old job, so if I find the code, I will post the workaround – Hicham May 28 '20 at 19:25

0 Answers0