converting rows to clumns using shell script

I have a script which converts rows to columns.
file_name=$1
mailid=$2
#CREATE BACKUP OF ORIGINAL FILE
#cp ${file_name}.xlsx ${file_name}_temp.xlsx
#tr '\t' '|' < ${file_name}_temp.xlsx > ${file_name}_temp.csv
#rm ${file_name}_temp.xlsx
pivot_row=`head -1 ${file_name}`
sed 1d ${file_name}>Sandeep
print "QUARTER\tMETRIC\tMETRIC_VALUE" > pivot_results.xlsx
#LOOP WHILE ROWS ARE LEFT
while IFS= read line
do
counter=1
curr_line=$line
curr_metric=`echo $line | cut -f1 -d","`
curr_value="dummy"
#LOOP WHILE COLUMN VALUES FOR THE CURRENT ROW ARE NOT NULL
while [[ $curr_value != "" ]];
do
((counter=counter+1))
curr_value=`echo $line | cut -f${counter} -d","`
if [[ $curr_value != "" ]]; then
curr_pivot_value=`echo $pivot_row | cut -f${counter} -d","`
print "${curr_pivot_value}\t${curr_metric}\t${curr_value}" >> pivot_results.xlsx
fi
done
done < Sandeep
rm Sandeep
echo "Pivoting completed successfully!!"
uuencode pivot_results.xlsx pivot_results.xls | mailx -s PIVOT $mailid
echo "Result mailed to specified id!!"
for example the input is like this
1990 1991
kiran 201 202

and the output should be like this

1990 kiran 201
1991 kiran 202

but iam getting the output as

1990 kiran 201
1991
kiran 202

one column is going down.any body can help me.thanks in advance

1 Like