#!/bin/bash
# Copyright 2010-2014 Chad Lemmen http://www.lemmen.com

# Convert a Fintech CSV file to import into an Informix database

# Delete the first line of the file, which is the column headings
# Add quotes between any commas missing them ,, do twice in case of ,,,,
# Substitute "," with |
# Substitute " with nothing
# Substitute , with | on the end of the line.
# Add a pipe to the end of line so number of fields is correct.
cat $1 | sed -e '1d' \
             -e 's/,,/,"",/g' -e 's/,,/,"",/g' \
             -e 's/","/|/g' \
             -e 's/"//g' \
             -e 's/,$/|/g' \
             -e 's/$/|/g'

#awk -F"\"" '{for(i=1;i<=NF;i++){if(i%2)gsub(",","|",$i)}}1' OFS= <file>

