You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, thank you for developing 'GoAWK' with great csv/tsv support!
I am trying to implement the filter command of Miller with the -H argument of GoAWK:
mlr --icsv --opprint filter '$color == "red"' example.csv
color shape flag k index quantity rate
red square true 2 15 79.2778 0.0130
red circle true 3 16 13.8103 2.9010
red square false 4 48 77.5542 7.4670
red square false 6 64 77.1991 9.5310
Yeah, this isn't the easiest with GoAWK right now. At present you either have to hard-code the field names in BEGIN:
# hard-code field names in BEGIN
$ goawk -icsv -H 'BEGIN { print "color,shape,flag,k,index,quantity,rate" } @"color" == "red"' example.csv
color,shape,flag,k,index,quantity,rate
red,square,true,2,15,79.2778,0.0130
red,circle,true,3,16,13.8103,2.9010
red,square,false,4,48,77.5542,7.4670
red,square,false,6,64,77.1991,9.5310
Or define a reusable print_fields function that loops over FIELDS and prints them out in CSV format, and then call that once (you can't call it in BEGIN as FIELDS is not set yet then).
I wouldn't mind designing a better API for this, but I'm not sure what it would look like. With CSV output mode, you can print arbitrary fields, so I'm not sure where the names would come from. Feel free to make suggetsions. See also #127 (but I don't love that API either).
First, thank you for developing 'GoAWK' with great csv/tsv support!
I am trying to implement the
filter
command ofMiller
with the -H argument ofGoAWK
:https://miller.readthedocs.io/en/latest/10min/
With -H argument,
NR==1
means the second line in GoAWK.Using
FIELDS
does not seem to make it easier:Maybe just combine
head -n 1 3.tsv
withgoawk -itsv -H 'NR == 1 {print $0} ' 3.tsv
? It would mean two processes instead of one.My current working function that implements the filter command of
mlr
:The text was updated successfully, but these errors were encountered: