Below is a bash shell script for taking in a csv file and spitting out rows formatted the way I want (Some more changes are there, but I only kept the array affecting ones below to show).
FILENAME=$1
cat $FILENAME | while read LINE
do
OIFS=$IFS;
IFS=","
columns=( $LINE )
date=${columns[4]//\"/}
columns[13]=${columns[13]//\"/}
columns[4]=$(date -d $date +%s)
newline=${columns[*]}
echo $newline
IFS=$OIFS;
done
I'm using GNU bash v 4.1.2(1)-release for CentOS 6.3. I've tried putting quotes like
newline="${columns[*]}"
Still no luck.
Following is sample data line
112110120001299169,112110119001295978,11,"121.119.163.146.1322221980963094","2012/11/01"
It seems like it should be outputting the array into a comma delimited string. Instead, the string is space delimited. Anyone know the reason why?
I suspect it has something to do with the fact that if I echo out $IFS in script it's an empty string, but when I echo out "${IFS}" it's then the comma I expect.
Edit: Solution
I found the solution. When echoing out $newline, I have to use quotes around it, i.e.
echo "$newline"
Otherwise, it uses the default blanks. I believe it has something to do with bash only subbing in for the IFS when you force it to with the quotes.