ezrosent / frawk

an efficient awk-like language
Apache License 2.0
1.24k stars 34 forks source link

script file and data file needs to be provided in certain order #65

Closed alperyilmaz closed 2 years ago

alperyilmaz commented 2 years ago

When I was running the file info/scripts/groupby.sh I encountered an error at the following line:

time $FRAWK -bllvm -F'\t' -f "$SCRIPT_FILE" "${TSV}"

When I was trying to trıubleshoot the problem I noticed that

cat datafile | frawk -f scriptfile   # works
frawk datafile -f scriptfile         # works
frawk -f scriptfile datafile         # fails

after trying different options, I found out that in case of frawk -f scriptfile datafile the datafile needs to be provided with --. Let me demonstrate the case:

frawk works fine with pipe:

$ echo -e "a,b,c\n1,2,3\n4,5,6"
a,b,c
1,2,3
4,5,6

$ echo -e "a,b,c\n1,2,3\n4,5,6" | frawk -icsv '{ print $2; }'
b
2
5

If we save the script as file, it woks fine in pipe

$ echo '{ print $2; }' > test.awk
$ echo -e "a,b,c\n1,2,3\n4,5,6" | frawk -icsv -f test.awk
b
2
5

if both data and script are from file, then fails

$ echo -e "a,b,c\n1,2,3\n4,5,6" > test.dat
$ frawk -icsv -f test.awk test.dat
Unrecognized token `,` found at line 3, column 4:line 3, column 5
Expected one of "\n", "[" or "{"

workaround is using --

$ frawk -icsv -f test.awk -- test.dat
b
2
5

Not sure if this is bug or a feature but still it would be great if frawk can be drop-in replacement for awk, by simply replacing awk with frawk in scripts , everything should work. So, it would be great if frawk can run just like awk where datafile is provided after script file.

I'm using frawk version 0.4.2 in Linux.

ezrosent commented 2 years ago

Hi! I think this is fixable. I agree that frawk should be close to other awks, where possible. I'll follow up soon.

ezrosent commented 2 years ago

I believe this is fixed in the commit above, which is included in frawk version 0.4.4. Let me know if you still notice problems along these lines, and thanks again for the report.

alperyilmaz commented 2 years ago

compiled 0.4.4 and issue is fixed.. thanks..