Extract substructure from a text file using bash or python

Posted by Werner on Stack Overflow See other posts from Stack Overflow or by Werner
Published on 2010-03-16T17:54:16Z Indexed on 2010/03/16 18:11 UTC
Read the original article Hit count: 157

Filed under:
|

Hi,

I have a huge text file, which follows the structure:

SET
TAG1
...
...
SET
...
SET
TAG2
...
...
SET
...
...

I would like to extract for a specific TAG, (i.e. TAG54) its individual "substructure", which would be

SET
TAG54
...
...
SET

Each substructure, for a given TAG_i contains always:

first line:SET second line:TAG_i (in this case TAG54) an arbitrary number of lines last line:SET

I wonder what would be the best way to do this, whether in bash or python, so for a given TAG, one can "extract" this substructure.

Thanks

© Stack Overflow or respective owner

Related posts about bash

Related posts about python