The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 05-28-2009
chowdhut chowdhut is offline
Registered User
  
 

Join Date: May 2009
Location: CT, USA
Posts: 4
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


Now I know my columns in File 2 , I know my number of rows in File 2 from File 1,
I need to process Cloumn 4 from File 1 and paste in File 2 , thinking -->

I need a way to form a string for each values in column 4 of File 1 seprated by '|' and
that string will append for each line of File 2 based on:

Need to figure out for each unique column 1 and column 2 combination in File 1
, I need to pick the column 4 values and append next to the applicable row in File 2
and when I do so the string values with column 4 for column 3 of File 1 needs to match the header order of File 2


hope I am not making my explanation complicated :-(

Last edited by chowdhut; 05-28-2009 at 04:22 PM..