1st: This is a UNIX and Linux forum. Unless explicitly told otherwise, we do not expect input files using DOS <carriagereturn><newline> line terminators; we expect UNIX and Linux <newline> line terminators. So all of the code we suggested that adds quotes ends up with a final field that just contains a quoted <carriagereturn> character.
2nd: Running the following script with the A4.txt that you provided:
#!/bin/ksh
sed 's/|/","/g; s/^/"/; s/$/"/' A4.txt > A5sed.txt
awk -F'|' -v OFS='","' 'NF{$1 = $1; $0 = "\"" $0 "\""}1' A4.txt > A5q.txt
awk -F'|' -v OFS=',' '{$1 = $1}1' A4.txt > A5nq.txt
produces the following in the three output files (shown using cat -v
to maek the carriage returns visible:
$ cat -v A5sed.txt
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 250000.00"," 121232.87"," 0.00","B64C8100 ","08/04/2014 ","2014-08-19-00.47.32.050493 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 500000.00"," 242465.75"," 0.00","B64C8100 ","08/04/2014 ","2014-08-19-00.47.32.050627 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 315285.83"," 152882.45"," 0.00","B64C8100 ","01/01/0001 ","2014-08-19-00.45.47.744917 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 520376.42"," 250916.73"," 0.00","B64C8100 ","08/04/2014 ","2014-08-19-00.47.20.793454 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 1000131.51"," 482246.54"," 0.00","B64C8100 ","08/04/2014 ","2014-08-19-00.47.20.793644 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 150037.33"," 72344.30"," 0.00","B64C8100 ","08/04/2014 ","2014-08-19-00.46.47.306701 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 646358.39"," 311668.70"," 0.00","B64C8100 ","08/04/2014 ","2014-08-19-00.47.08.815658 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 110000.00"," 53041.08"," 0.00","B64C8100 ","08/04/2014 ","2014-08-19-00.46.50.346962 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 158213.08"," 160383.33"," 750.00","B64C8100 ","08/23/2012 ","2014-08-19-00.45.33.451061 ","^M"
"DEP","2","08/19/2014","SECOND TEST FILE DESCRIPTION "," 140383.43"," 132266.13"," 1400.00","B64C8100 ","09/06/2012 ","2014-08-19-00.45.33.451359 ","^M"
$
The contents of A5q.txt
are identical to the contents of A5sed.txt
.
$ cat -v A5nq.txt
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 250000.00, 121232.87, 0.00,B64C8100 ,08/04/2014 ,2014-08-19-00.47.32.050493 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 500000.00, 242465.75, 0.00,B64C8100 ,08/04/2014 ,2014-08-19-00.47.32.050627 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 315285.83, 152882.45, 0.00,B64C8100 ,01/01/0001 ,2014-08-19-00.45.47.744917 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 520376.42, 250916.73, 0.00,B64C8100 ,08/04/2014 ,2014-08-19-00.47.20.793454 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 1000131.51, 482246.54, 0.00,B64C8100 ,08/04/2014 ,2014-08-19-00.47.20.793644 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 150037.33, 72344.30, 0.00,B64C8100 ,08/04/2014 ,2014-08-19-00.46.47.306701 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 646358.39, 311668.70, 0.00,B64C8100 ,08/04/2014 ,2014-08-19-00.47.08.815658 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 110000.00, 53041.08, 0.00,B64C8100 ,08/04/2014 ,2014-08-19-00.46.50.346962 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 158213.08, 160383.33, 750.00,B64C8100 ,08/23/2012 ,2014-08-19-00.45.33.451061 ,^M
DEP,2,08/19/2014,SECOND TEST FILE DESCRIPTION , 140383.43, 132266.13, 1400.00,B64C8100 ,09/06/2012 ,2014-08-19-00.45.33.451359 ,^M
$
All of these are exactly what we would expect for the input file you provided!
To get the output you showed us, you had to use different commands than those we suggested you use. (Most likely you are using the wrong quotes in -F'|'
or are using something like �
instead of |
.)
To correctly process your DOS files on UNIX systems, change the DOS line terminators in your input file to UNIX line terminators using:
dos2unix input output
where input is a DOS file and output is the name of the file you want to create with corrected line terminators.