how to extract certain text from file?
Question: i want to extract certain section of the text file. my input file:

    
    
    -- num cell port function safe [ccell disval rslt]
       "17 (BC_1, CLK, input, X)," &
       "16 (BC_1, OC_NEG, input, X), " &-- Merged input/
       " 8 (BC_1, D(8), input, X)," &  -- cell 16 @ 1 -> Hi-Z
       " 7 (BC_1, Q(1), output3, X, 16, 1, Z)," &
       " 0 (BC_1, Q(8), output3, X, 16, 1, Z)";
    

and i need the output to be as such:

    
    
    num cell port function safe ccell
       17 BC_1 CLK input X 
       16 BC_1 OC_NEG input X  
       16 BC_1 * control 1 
        8 BC_1 D8 input X   
        7 BC_1 Q1 output3 X 16 1  
        0 BC_1 Q8 output3 X 16 1 
    

so far i tried below code but it gave index error. pls advise.

    
    
    import re
    lines=open("input.txt",'r').readlines()
    
    for line in lines:
        a=re.findall(r'\w+',line)
        print re.findall(r'\w+',line)
        print a[0],a[1],a[2],a[3],a[4],a[5],a[6]
    

i'm using python 2.6.6 and error as below:

    
    
    ['num', 'cell', 'port', 'function', 'safe', 'ccell', 'disval', 'rslt']
    num cell port function safe ccell disval
    ['17', 'BC_1', 'CLK', 'input', 'X']
    17 BC_1 CLK input X
    Traceback (most recent call last):
      File "C:\Users\ctee1\Desktop\pyparsing\outputparser.py", line 39, in <module>
        print a[0],a[1],a[2],a[3],a[4],a[5],a[6]
    IndexError: list index out of range
    


Answer: 
    sed -r 's/(disval|rslt)//; s/(.)--.*/\1/; s/[^[:alnum:]_]//; s/ +$//'
    

