Skip to content

Instantly share code, notes, and snippets.

@kozross
Created March 22, 2017 03:42
Show Gist options
  • Save kozross/9ffeb6af200f95d3a0c5450d0abb8afd to your computer and use it in GitHub Desktop.
Save kozross/9ffeb6af200f95d3a0c5450d0abb8afd to your computer and use it in GitHub Desktop.
# I have the following Gawk invocation, which correctly only prints certain fields of a file in a comma-separated list
#
# gawk -F ',' -v NLINES=$(wc -l < members.csv) 'NR > 1 { printf("%s", $4) } NR != nlines && NR > 1 { printf(",") }' members.csv
#
# I'm trying to translate this into an actual script, and I have the following:
#!/usr/bin/gawk -f
FS = ","
NLINES = system("wc -l <" ARGV[1])
NR > 1 { printf("%s", $4) }
NR != NLINES && NR > 1 { printf(",") }
# However, this doesn't work correctly when invoked as 'script.awk members.csv'
# It instead dumps the whole line each time, followed by the count on a new line
# What went wrong in translation here?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment