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 -->
  #4 (permalink)  
Old 09-15-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
awk -v str="MANDT SERAIL SERSCHA SEREX EQTYP BSTVP" '
NR == 1 {
    n=split( str , arr , " " )
    for( i = 1; i <= n ; ++i )
        arr_ac[$i]=i
    for( i = 1; i <= n ; ++i )
        col[i]=arr_ac[arr[i]]
    print str 
}
NR > 1 {
    for(i = 1; i <= n ; ++i )
        printf("%s ",$col[i])
    printf("\n")
}
' file >> final_data.txt