Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect lines stack python
    primarykey
    data
    text
    <p>i writen this code:</p> <pre><code>import os import re import string ## Path = 'C:/RESULT/BATCH/' ## Nfile = 'Skin_Refined_v05' f=open(Path + Nfile + '.inp') n=open(Path + 'newfile.inp', 'w') for lines, text in enumerate(f): found = text.find('*SURFACE') while found &gt; -1: print found, lines, text found = text.find('*SURFACE', found + 1) n.write(text) ## f.close() n.close() </code></pre> <p>This is what *.inp looks like (usually about 30Mb)</p> <pre><code>*SURFACE, NAME = BOTTOM, TYPE = ELEMENT 40012646, S2 40012647, S2 40012648, S2 40012649, S2 40012650, S2 40012651, S2 *SURFACE, NAME = ALL_INT_TIE_1, TYPE = ELEMENT 40243687, S3 40243703, S3 40243719, S3 40243735, S3 40243751, S3 40243767, S3 ** *TIE, NAME = INTERNAL_TIE, POSITION TOLERANCE = 1.0 , ADJUST=NO SLAVE,MASTER *TIE, NAME = SKN_REF_1 ALL_INT_FRONT, ALL_EXT_FRONT *TIE, NAME = SKIN_LAT ALL_INT_LAT, ALL_EXT_LAT *TIE, NAME = SKIN_TIE_1 ALL_INT_TIE_1, ALL_INT_TIE_2 ** *SURFACE , NAME = TOP, COMBINE = UNION TOP_1 TOP_2 **HM_UNSUPPORTED_CARDS *END PART ***** </code></pre> <p>what he does it is clear. what I would like to achive is to get all the line between the *SURFACE that begin with a number, which then I will have to arrange differently, but I will worry about that later.</p> <p>I rewrote the code cos i could not get it to work as suggested, now it is creating the blocks as I need them, but how do i work on each block?</p> <p>I need to separate all the elements (number followed by S1, S2 and so on) and create groups for each block sorted by S1, S2 and so on the final result should look like</p> <p>*ELSET, ELSET=TOP_S1<br> 40221320, 40221306, 40221305, 40221304, 40221290, 40221289, 40221288, 40221274,<br> 40221273, 40221272, 40221258, 40221257, 40221256, 40221242, 40221241, 40221240,<br> *SURFACE, NAME = TOP, TYPE = ELEMENT<br> TOP_S1,S1 </p> <pre><code>import os import re import string ## Path = 'C:/RESULT/BATCH/' ## Nfile = 'Skin_Refined_v05' f=open(Path + Nfile + '.inp') n=open(Path + 'newfile.inp', 'w') in_surface_block = False; for line_num, text in enumerate(f): found = text.find('*SURFACE') if found &gt; -1: in_surface_block=True; print found, line_num, text surface_lines = [] continue if in_surface_block: m = re.match('\s*\d+\,\s*\w\d+',text) if m: mtext = m.group(0) ## p=surface_lines.append(text) print mtext ## ntext = surface_lines.append(m.group(0)) ## n.write(ntext) ## f.close() n.close() </code></pre> <p>I hope it is clear</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload