Hi,
Can anyone help with the below please?
I have written some code which takes an input file, and and prints the contents out to a new file - it then loops round and prints the same columns, but increments the ID column by 1 each time.
Input file;
NAME,1,15-Dec-15,
NAME,1,21-Dec-15,
NAME,1,31-Jan-16,
Expected output;
NAME,1,15-Dec-15,
NAME,1,21-Dec-15,
NAME,1,31-Jan-16,
NAME,2,15-Dec-15,
NAME,2,21-Dec-15,
NAME,2,31-Jan-16,
NAME,3,15-Dec-15,
NAME,3,21-Dec-15,
NAME,3,31-Jan-16,
VAR_ID=1
touch newfile.csv
while [ $VAR_ID -le 3 ]
do
while read line
do
echo $line | awk -v var="$VAR_ID" -F "," 'BEGIN {print $1 var $3}' >> newfile.csv
done < inputfile.csv
VAR_ID=`expr $VAR_ID + 1`
done
When i run currently, it just prints out the incremental numbers i.e.
1
1
1
2
2
2
3
3
3
Can anyone help please?