So far in my humble work.....
Code:
# For File 2, 1st I tried to create unique values from File 1's column 3
# and transpose those values as headers for File 2
awk -F":" '{print $3}' File1.txt | sort | uniq > tst.txt
# for each row of distinct 3rd column values of File 1 , create a file with column headers ( for now hard code first two columns USUBJID and CMSEQ)
awk -F "/n" '
BEGIN {OFS= "|"}
{
for (i=1;i<=NF;i++)
{arr[NR,i]=$i;}
}
END {
printf("USUBJID|CMSEQ|");
for(i=1;i<=NF;i++)
{
for(j=1;j<=NR;j++)
{printf("%s|",arr[j,i]);}
printf("\n");
}
}' tst.txt > temp1.txt
cp temp1.txt File2.txt
# each 1st and 2nd record in File1.txt file , needs to create a distinct row in File2.txt for 1st and 2nd columns usubjid|cmseq combo
awk -F':' '
{
SEQ[$1,"|",$2] = SEQ[$1,"|",$2];
}
END {
for (i in SEQ)
print i;
}' File1.txt >> File2.txt