I have the following csv file:
$ cat mycsv.csv
"1/30/2017 11:14:55 AM","I","M","k6.0.1","E","jim","JimK","JIM","jim@gmail.com","A","6.0.12”,”A”,”N”
"1/30/2017 11:14:55 AM","I","M","k6.0.1","E","jim","JimK","JIM","jim@gmail.com","A","6.0.12”,”A”,”N”
"1/30/2017 11:14:55 AM","I","M","k6.0.1","E","jim","JimK","JIM","jim@gmail.com","A","6.0.12”,”A”,”N”
Why does the following not print all the lines?
$awk -F "," '{printf}' mycsv.csv
","M","k6.0.1","E","jim","JimK","JIM","jim@gmail.com","A","6.0.12”,”A”,”N””
$awk -F "," '{printf $0}' mycsv.csv
","M","k6.0.1","E","jim","JimK","JIM","jim@gmail.com","A","6.0.12”,”A”,”N””
Both should print all the lines right? What am I doing wrong?
Best Answer
The first argument to
printf
, whether it's Cprintf()
or theprintf
utility orawk
'sprintf()
is required1 and is the format.You want:
here. If you don't want an output record separator, you can also do:
Or even:
(
{print}
is the default action, true is the default condition, but you need to specify at least one action or condition,1
is one way to say true).Though here,
tr
would be enough:Or if you still want one trailing newline character so that output is still text:
It also seems like your file has Microsoft-style CRLF line delimiters, so you may want to also delete the CR characters:
Or only the CRLF sequences with
awk
implementations that support more than single-characterRS
(which includesgawk
andmawk
but not macOSawk
):Or:
that is with the
\r
optional to handle either Unix or MS-DOS line delimiters.Or use things like
dos2unix
ord2u
to convert the file to Unix format first.Notes
1 the format argument to
printf
is required in the standard specification of theawk
utility. Ingawk
andmawk
omitting it results in an error. Inbusybox
awk
, it's equivalent toprintf ""
and inawk
derived from the original implementation (like onmacOS
), it's equivalent toprintf $0
(of little usefulness as it's still considered as a format, you'll still get an error if$0
contains%
characters).