So what I'm trying to do is for this: looking at the example CSV:
1,3917,3917,BGP=694|Ethernet=1610|LAG=3,Y
After the script is run, the output should look similar to:
1,3917,3917,BGP=694,Y
1,3917,3917,Ethernet=1610,Y
1,3917,3917,LAG=3,Y
One line of original CSV file that contained additional delimiters is now converted into 3 lines because there were three additional fields within the 4th column.
I've been working on it all day and this is what I've come up with. Will it work?
Code:
#!/usr/bin/ksh
if [ $# -ne 1 ];
then echo "Usage: read.sh filename";
exit 1;
fi
file="$1"
while read line
do
IFS='|'
set x $line
while [ a -le #$]
do
a=a+1
echo "`$1`,`$a`"
done
done < $1
/tcshwhen the script isksh? also you need to be a lot clearer about what it is that you're trying to do. start from the beginning, describe your actual goal, not the (possibly wrong or less-than-optimal) method you've chosen to implement....there may be a much better/easier way to do it, probably involvingawk– Craig Sanders Sep 6 '12 at 1:47awk) if I know one. If you don't understandawk, you should learn it! – Bernhard Sep 6 '12 at 5:39