Extract substructure from a text file using bash or python
- by Werner
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