Skip to main content

New answers tagged

0 votes

command-line tool to sum the values in a column of a CSV file

Using GNU awk 5.3 or newer for -k (or equivalently --csv): awk -k '{n+=$3} END{print n+0}' file See https://stackoverflow.com/questions/45420535/whats-the-most-robust-way-to-efficiently-parse-csv-...
Ed Morton's user avatar
  • 32.4k
0 votes

How to align fstab entries easily

Late to the party, simple solution cp /etc/fstab ~/oldfstab grep '^#' /etc/fstab > ~/newfstab grep -v '^#' /etc/fstab | column -t >> ~/newfstab cp ~/newfstab /etc/fstab
mark's user avatar
  • 111
1 vote

command-line tool to sum the values in a column of a CSV file

Using csvsql from the csvkit set of tools, which was what you originally tried to use: $ csvsql -I --query 'SELECT SUM("data 1") FROM file' file | tail -n +2 19 This inserts the CSV data ...
Kusalananda's user avatar
  • 339k
4 votes
Accepted

command-line tool to sum the values in a column of a CSV file

Miller handles quoted CSVs natively, so the following should work: mlr --csv --headerless-csv-output stats1 -a sum -f 'data 1'
muru's user avatar
  • 73.9k
1 vote

command-line tool to sum the values in a column of a CSV file

I put your CSV into a file a.csv and did the summing as follows: cat a.csv | awk -F, '{ if($3 !~ /data*/ ){ total+= $3} } END { print "sum=" total}' This is using awk with a comma as a ...
user1683793's user avatar

Top 50 recent answers are included