Hello
Sorry if this is a bit simple for you folks but for this born again newbie itsn't.I thought I had posted this but cant find it, if I have sorry and I will try to delete the double up, if my first post was deleted because I dont belong here then sorry and I assume the same thing will happen to this post
I want to scan a file containing lines such as
P5050006 809 x3760
P5050007 3
P5050008 508 605 809
P5050009 57 1000
P5050010 124 596 7545 809
where S1 is a photo number and the remaining fields are shirt numbers etc appearing in that photo.
For every shirt number etc I want to list the photos in which it appears so that the output file would look something like
3 P5050007
57 P5050009
124 P5050010
596 P5050010
605 P5050008
809 P5050006 P5050008 P5050010
1000 P5050009
I am half way there via
awk ' { for (j=2; j <= NF; j++) {
rpn[$j] = rpn[$j] sprintf("%s\t", $1)
printf("%s\t %s\t %s\n",$j,(nopfr[$j] +1),rpn[ $j ])
nopfr[$j] = nopfr[$j] + 1
}
} ' file1 > file2
The obvious problem being that the output lists the sequential "rpn" values for a give shirt number eg for shirt number 809 I get
809 1 P5050006
809 2 P5050006 P5050008
809 3 P5050006 P5050008 P5050010
( ignore nopfr[$j] and $2 of the output they are just to let me see what is happening)
Really all I want to out put is the final value i.e.
809 3 P5050006 P5050008 P5050010
So if some one woyuld be kind enought to help I would be very grateful.
Thanks
Sorry if this is a bit simple for you folks but for this born again newbie itsn't.I thought I had posted this but cant find it, if I have sorry and I will try to delete the double up, if my first post was deleted because I dont belong here then sorry and I assume the same thing will happen to this post
I want to scan a file containing lines such as
P5050006 809 x3760
P5050007 3
P5050008 508 605 809
P5050009 57 1000
P5050010 124 596 7545 809
where S1 is a photo number and the remaining fields are shirt numbers etc appearing in that photo.
For every shirt number etc I want to list the photos in which it appears so that the output file would look something like
3 P5050007
57 P5050009
124 P5050010
596 P5050010
605 P5050008
809 P5050006 P5050008 P5050010
1000 P5050009
I am half way there via
awk ' { for (j=2; j <= NF; j++) {
rpn[$j] = rpn[$j] sprintf("%s\t", $1)
printf("%s\t %s\t %s\n",$j,(nopfr[$j] +1),rpn[ $j ])
nopfr[$j] = nopfr[$j] + 1
}
} ' file1 > file2
The obvious problem being that the output lists the sequential "rpn" values for a give shirt number eg for shirt number 809 I get
809 1 P5050006
809 2 P5050006 P5050008
809 3 P5050006 P5050008 P5050010
( ignore nopfr[$j] and $2 of the output they are just to let me see what is happening)
Really all I want to out put is the final value i.e.
809 3 P5050006 P5050008 P5050010
So if some one woyuld be kind enought to help I would be very grateful.
Thanks