|
I Am Stumped, Please Help
I have a CSV file that I am trying to parse with awk in a table. I think I am going about this the wrong way. I can't get the awk arrays to output with a tab between them in one line. They print out vertically and I need them to print out horizontally. WHAT AM I DOING WRONG?? I want to know if it's
possible to do in awk, because it will become a function in a bigger script if this ever works out.
csv input file:
Code:
175,5 ,0,2 ,4 ,0,1 , , , , , , , , , , , , , , , , , , , , , , , , ,3
176,5 ,0,2 ,4 ,0,1 , , , , , , , , , , , , , , , , , , , , , , , , ,3
177,14 ,0,2 ,7 ,0,2 ,11 ,0,2 , , , , , , , , , , , , , , , , , , , , , ,3
178,5 ,0,2 ,2 ,0,2 , , , , , , , , , , , , , , , , , , , , , , , , ,3
179,5 ,0,2 ,4 ,0,1 , , , , , , , , , , , , , , , , , , , , , , , , ,3
18 ,8 ,0,1 ,13 ,0,2 ,3 ,0,2 ,3 ,0,2 , , , , , , ,3 ,0,2 ,3 ,0,2 ,3 ,0,2 ,3 ,0,2 ,3
180,5 ,0,1 ,4 ,0,2 ,12 ,0,2 , , , , , , , , , , , , , , , , , , , , , ,3
181,1 ,0,2 ,4 ,0,2 ,12 ,0,2 , , , , , , , , , , , , , , , , , , , , , ,3
182,14 ,0,2 ,7 ,0,2 ,3 ,0,1 ,3 ,0,1 , , , , , , , , , , , , , , , , , , ,3
script:
Code:
#!/usr/bin/nawk -f
BEGIN {
FS=";"
}
{
x[$2*1"-"$4*1]=x[$2*1"-"$4*1] " " $32 * 1000 + $1"-1"ORS;
x[$5*1"-"$7*1]=x[$5*1"-"$7*1] " " $32 * 1000 + $1"-2"ORS;
x[$8*1"-"$10*1]=x[$8*1"-"$10*1] " " $32 * 1000 + $1"-3"ORS;
x[$11*1"-"$13*1]=x[$11*1"-"$13*1] " " $32 * 1000 + $1"-4"ORS;
x[$14*1"-"$16*1]=x[$14*1"-"$16*1] " " $32 * 1000 + $1"-5"ORS;
x[$17*1"-"$19*1]=x[$17*1"-"$19*1] " " $32 * 1000 + $1"-6"ORS;
x[$20*1"-"$22*1]=x[$20*1"-"$22*1] " " $32 * 1000 + $1"-7"ORS;
x[$23*1"-"$25*1]=x[$23*1"-"$25*1] " " $32 * 1000 + $1"-8"ORS;
x[$26*1"-"$28*1]=x[$26*1"-"$28*1] " " $32 * 1000 + $1"-9"ORS;
x[$29*1"-"$31*1]=x[$29*1"-"$31*1] " " $32 * 1000 + $1"-10"ORS;
}
END {
for ( i in x )
printf "%-3s%-4s\n%-8s\n%-7s\n","UFC ",i,"--------",x[i]
}
output:
Code:
output:
UFC 5-2
--------
3175-1
3176-1
3178-1
3179-1
UFC 5-1
--------
3180-1
UFC 14-2
--------
3177-1
3182-1
UFC 8-1
--------
3018-1
UFC 1-2
--------
3181-1
UFC 4-1
--------
3175-2
3176-2
desired output:
Code:
UFC 5-2 UFC 5-1 UFC 14-2
-------- -------- --------
3175-1 3180-1 3177-1
3176-1 3182-1
3178-1
3179-1
I hope you get the idea of the desired output, too hard to put everything in thread. I want the output to be in a table format, and sorted by UFC numbers from left to right.
Thanks in advance.
|