Hi everyone,

I have a huge data file and it goes on like this.

62813,     61344,     68229,     68234,     61349,     61345,     68230   
     62814,     61345,     68230,     68235,     61350,     61346,     68231    
     62815,     61346,     68231,     68236,     61351,     61347,     68232      
     62816,     61347,     68232,     68237,     61352,     51631,     51573    
*ELEMENT,TYPE=S4,ELSET=one                                        
     62817,         1,         2,         4,         3
     62818,         3,         4,        14,        13
     62819,        13,        14,        20,        19
     62820,         2,        25,        26,         4
*ELEMENT,TYPE=S4,ELSET=two                                     
     67450,       241,       242,       244,       243
     67451,       243,       244,       246,       245
     67452,       242,       253,       254,       244
     67453,       244,       254,       255,       246

i need to delete the following lines from the file

*ELEMENT,TYPE=S4,ELSET=one                                        
     62817,         1,         2,         4,         3
     62818,         3,         4,        14,        13
     62819,        13,        14,        20,        19
     62820,         2,        25,        26,         4

so that the final output looks like this

62813,     61344,     68229,     68234,     61349,     61345,     68230   
     62814,     61345,     68230,     68235,     61350,     61346,     68231    
     62815,     61346,     68231,     68236,     61351,     61347,     68232      
     62816,     61347,     68232,     68237,     61352,     51631,     51573    
*ELEMENT,TYPE=S4,ELSET=two                                     
     67450,       241,       242,       244,       243
     67451,       243,       244,       246,       245
     67452,       242,       253,       254,       244
     67453,       244,       254,       255,       246

Thank you

Recommended Answers

All 2 Replies

Do you have to delete only the first five lines ?????

How many Giga/Terabytes is this huge file? You need only to remove this specific lines, not certain element blocks?

This code drops sections that are in discard_blocks set.

discard_blocks = {'*ELEMENT,TYPE=S4,ELSET=one' }
with open('data.txt') as datain, open('data_out.txt', 'w') as dataout:
    writeout=True
    for line in datain:
        if line.rstrip() in discard_blocks:
            writeout = False
        elif line.startswith('*ELEMENT'):
            writeout = True
        if writeout:
            dataout.write(line)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.