Hello all,
I have a file that uses the pipe character as a separator since I assumed that most of my clients wouldn't use the pipe character in their data. Apparently I was wrong, but I compensated for this by specifying that any fields using the pipe character need to be wrapped in double quotes. Unfortunately, they haven't done this, but I can't have them re-export their file just yet because I need their old data, so I need to manually update their old data file to properly quote the field that has pipe characters in it.
Some of the lines are correct with 16 separators and thus 16 fields whilst some of the lines have 18 separators for only 16 fields. I need to wrap the 10th field with quotation marks only if it has 18 separators instead of 16. I have a Linux box at my disposal with awk, sed, grep, etc. and would love to have a way to script this so I don't have to do it manually.
A simplified example input/output with only 5 and 7 separators (quoting the 4th field) would be:
# Input
Field 1|Field 2|Field 3|Field 4|Field 5|Field 6
Field 1|Field 2|Field 3|Field | with | pipes|Field 5|Field 6
# Output
Field 1|Field 2|Field 3|Field 4|Field 5|Field 6
Field 1|Field 2|Field 3|"Field | with | pipes"|Field 5|Field 6
# Optional output if it is easier
Field 1|Field 2|Field 3|"Field 4"|Field 5|Field 6
Field 1|Field 2|Field 3|"Field | with | pipes"|Field 5|Field 6
Any help would be enormously appreciated!