awk FPAT does not work in AppleScript, but does work in the Terminal
The issue:
I have an awk command that uses FPAT to ignore comma's in a CSV record. This command works in the Terminal (default zsh shell):
awk -v FPAT='"[^"]*"|[^,]+' 'NF==6 {split($NF, a, /\. # /)} NR!=1&&NF<=6 {print a[5],$5,$3,$4} ' input.txt
Sample record:
http://publications.europa.eu/resource/cellar/3befa3c3-a9af-4dac-baa2-92e95cb6e3ab,http://publications.europa.eu/resource/cellar/3befa3c3-a9af-4dac-baa2-92e95cb6e3ab.0002,ECLI:EU:C:1985:443,61984CJ0239,Gerlach,"Judgment of the Court (Third Chamber) of 24 October 1985. # Gerlach & Co. BV, Internationale Expeditie, v Minister van Economische Zaken. # Reference for a preliminary ruling: College van Beroep voor het Bedrijfsleven - Netherlands. # Article 41 ECSC - Anti-dumping duties. # Case 239/84."
However, it does not work in my AppleScript, where I have entered it (with escaping) like this.
set r1 to do shell script "awk -v FPAT='\"[^\"]*\"|[^,]+' '{print a[5],$5,$3,$4
}' <<<" & quoted form of theInput
With this command, awk still treats a space as the field delimiter. In other words, it appears to ignore the `FPAT` completely. This is very clear when one replaces the `print` statement with a simple `print $1`.
Solutions tried:
- I have tested the command in the Terminal with the sh shell (which the do shell script command uses by default) and this still works perfectly so that does not seem to be the problem.
- When I do
awk -W version
the output is:
GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)