I got around using an intermediate character (in the past I have used some of the old ASCII punch card/paper tape control characters 28-32) by brute forcing first and last quote removal. There should be no need to exclude a character now.
awk -F, 'BEGIN { OFS=","; comm=22} #Convert any "," in comments to ";"
{ for(i=comm+1; i<=NF; i++) {$comm=$comm";"$i}
if (NF>comm) NF=comm; print $0 }' |
awk -F, 'BEGIN { OFS = ","
# Read in Known Fail List
getline < "'"$failListFile"'"; getline < "'"$failListFile"'"; getline < "'"$failListFile"'" # Header Rows
while (getline < "'"$failListFile"'") { split( $0, a, ","); i=a[1]a[2]a[3]; gsub ( " ", "", i ); failMessage=a[6]
failStart=a[4]? a[4] : "0000 01 01 00 00 00"
failEnd=a[5]? a[5] : "9999 12 31 23 59 59" }
close("'"$failListFile"'")}
!($7 == "" || $9 == "" || $10 == "" || $11 == "" || $12 == "") {
split($7,a," "); split(a[1],d,"/"); split (a[2],t,":")
month = sprintf("%02d",d[1]); day = sprintf("%02d",d[2]) #All 2 digits
year = 2000 + d[3] % 100 #Force 4 digit year
hour = sprintf("%02d",t[1]); min = sprintf("%02d",t[2])
date = month"/"day"/"year; time = hour":"min
$7 = date" "time
if ( $19 == "Y" ) $19 = "V"; #Allowing for older Raw Data Files and Archives
else if ( $19 == "N" ) $19 = "I"; #to use the older YNE vs VIE Valid column.
else if ( $19 =="" ) $19 = "I" #if valid column manually erased, treat as Invalid
# $22 = $22 ~ /^\".*\"$/ ? $22 : "\""$22"\"" # put quotes around comment if Excel did not already
gsub(/^\"/,"",$22); gsub(/\"$/,"",$22); gsub (/\"\"/,"\x27\x27", $22); $22 = "\""$22"\"" #remove wrapping quotes, Change "" (.csv representation of ") to '', rewrap in quotes
i=$1$6$8; gsub ( " ", "", i )
if ( $18 == "FAIL" && i in failMessage ) { now = mktime(year" "month" "day" "hour" "min" 00")
if ( now >= mktime(failStart) && now <= mktime(failEnd) ) {
if ($22 == "\"\"") gsub ( "\"$", "Known Fail: "failMessage"\"", $22 )
else gsub ( "\"$", "|Known Fail: "failMessage"\"", $22 ) } }
print $0
}'
Took me a long time to figure out that you could not escape ' characters in AWK with \' or a whole bunch of other things with and without a variable declaration (but you can do so in BASH with the awk -v option), so I used \x27
Excel column 22:
Fake data: comment with "quotes"
Fake data, comment, with, commas,,,
.CSV column 22:
"Fake data: comment with ""quotes"""
"Fake data, comment, with, commas,,,"
Output of script column 22:
"Fake data: comment with ''quotes''"
"Fake data, comment, with, commas,,,"
Mike