I have a CSV file that I'm parsing in bash that, for one column, has more than one value for some rows. For example, a line with multiple values may look like
name,12,120,east,"sw1,sw2,sw3"
But not all rows have it. Some may look like
name,10,141,west,sw5534a
What I'm trying to do is if that column has quotes in it to remove them and set the variable to just sw1,sw2,sw3
Relevant parts of the script:
#!/bin/bash
INPUT=file.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read name building id region parents
do
echo "
....snip....
parents $parents"
The output I want for $parents should be sw1,sw2,sw3
but right now it spits out as "sw1,sw2,sw3"
I've tried messing around with regex matching in a conditional if the column has a comma to remove the first and last two characters, but I couldn't get it to work. Either it would remove the first s
and the last 3
or it would just error out.
Any suggestions appreciated!