I have a CSV file of approx 1000 rows, and where I'm supposed to import it, I get an error on row 700. However, the entries in this CSV contain newlines (and are quoted), and thus I cannot really quickly use awk
or similar to show what is row 700.
So I found Is there a robust command line tool for processing csv files?, and installed both csvfix
and csvkit
; however it seems none of these applications supports simply specifying a row number (or a range of rows), and outputting them. For instance:
$ csvfix help echo
echo input CSV data to output
usage: csvfix echo [flags] [file ...]
where flags are:
-ibl ignore blank input lines
-sep s specify CSV field separator character
-rsep s as for -sep but retain separator on output
-osep s specifies output separator
-hdr s write the string s out as a header record
-ifn ignore field name record
-smq use smart quotes on output
-sqf fields specify fields that must be quoted
-o file write output to file rather than standard output
-skip t if test t is true, do not process or output record
I would have thought echo
is what I need, as soon as I could specify which row(s) is(are) to be echoed, but when I look at http://neilb.bitbucket.org/csvfix/manual/csvfix16/csvfix.html?unique.html, only columns are described.
How could I use these tools - or other tools - to simply dump say row 700 (or rows 702-705) from a 1000-row CSV to stdout?
EDIT: Found (http://neilb.bitbucket.org/csvfix/manual/csvfix16/ExpressionLanguage.html) that csvfix
has:
csvfix find -if '$line == 407' data.csv
... however, this is indeed line number and not row number; so if the row starts at line 406, then breaks to line 407, and ends at 407; then the above command will output nothing - but if you go one line back, -if '$line == 406'
, then the row is dumped. This is useful too, but still isn't a row number....
csvtool head 700
orcvstool sub 702 1 4 20
? http://colin.maudry.com/csvtool-manual-page/ β rudimeier Sep 27 '16 at 17:04csvtool
β sdbbs Sep 27 '16 at 17:04