The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 -->
  #6 (permalink)  
Old 09-18-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,538
here's an alternative in Python:
Code:
def transpose(matrix):        
        return [[matrix[y][x] for y in range(len(matrix))]for x in range(len(matrix[0]))]


all = open("input.txt").readlines()
lookupstring = ['MANDT', 'SERSCHA','SERAIL' , 'SEREX', 'EQTYP', 'BSTVP']
listing = [ i.split() for i in all ] 
results =  transpose(listing)
final= [ r for items in lookupstring for r in results if items == r[0] ]
for i in transpose(final):
        print ','.join(i)
Input:
Code:
MANDT SERAIL EQTYP SERSCHA SEREX BSTVP
510   hsgdfs 44    sercha  sex1  bst233
510   bg     89    fg      23    98
510   gh     89    we      sew   mn
Output:
Code:
/home>python test.py
MANDT,SERSCHA,SERAIL,SEREX,EQTYP,BSTVP
510,sercha,hsgdfs,sex1,44,bst233
510,fg,bg,23,89,98
510,we,gh,sew,89,mn