2
2
3
3
# Script: csv.ksh
4
4
# Author: Ben Altman (csv.feedback.benalt at xoxy.net)
5
- # Description: Convert csv files from Excel in to a format using a different separators .
5
+ # Description: Convert csv files from Excel in to a format using a different separator .
6
6
#
7
7
# Usage: csv.bash [options] csv_file
8
8
# -i csv_file_field_separator (default is comma)
@@ -44,7 +44,7 @@ BEGIN {
44
44
if (! nl) nl = "\\n"
45
45
if (! fs) FS = ","; else FS = fs
46
46
if (! ofs) OFS = "|"; else OFS=ofs
47
- above line backs up FS for when rejoining fields containing FS in the case when it`s a pipe. Don`t join with [|] per the below
47
+ # above line backs up FS for when rejoining fields containing FS in the case when it`s a pipe. Don`t join with [|] per the below
48
48
gsub("[|]","[|]",FS) # Input separator containing a pipe replace "|" with "[|]"
49
49
}
50
50
@@ -60,6 +60,9 @@ BEGIN {
60
60
# 1. A field with no DQs is a simple field and we can move straight to the next field.
61
61
# 2. A field starting with a DQ can contain DQs, FS or multiple lines which we need to join.
62
62
63
+ # Exceptional even double quoted field where then entire field is "" is equal to blank without the double quotes
64
+ if ($i == "\"\"") $i=""
65
+
63
66
# If the field is not a simple field with no DQs at all
64
67
if (substr($i,1,1) == "\"") {
65
68
# while the field ENDS in even or no DQs it is joined to the next field, until odd quotes are joined ending the field...
0 commit comments