swaggerbox
05-28-2010, 11:54 PM
In C:\Sample I have over a thousand text files. Each text file contains multiple datasets that begins with the tag "<BTAG>" followed by a unique control ID and ends with the tag "<CTAG>" followed by the same unique control ID.
Is there a way to extract each of these datasets to a separate text file with the unique control ID as filename?
Sample file: Sample.txt
<BTAG> 111111
<1TAG> This is the first field
<2TAG> This is the second field
<3TAG> This is the third field
<4TAG> This is the fourth field
<CTAG> 111111
<BTAG> 222222
<1TAG> This is the first field
<2TAG> This is the second field
<CTAG> 222222
<BTAG> 333333
<1TAG> This is the first field
<2TAG> This is the second field
<1TAG> This is the third field
<2TAG> This is the fourth field
<1TAG> This is the fifth field
<2TAG> This is the sixth field
<CTAG> 333333
Desired output:
Filename 111111.txt
<BTAG> 111111
<1TAG> This is the first field
<2TAG> This is the second field
<3TAG> This is the third field
<4TAG> This is the fourth field
<CTAG> 111111
Filename 222222.txt
<BTAG> 222222
<1TAG> This is the first field
<2TAG> This is the second field
<CTAG> 222222
Filename 333333.txt
<BTAG> 333333
<1TAG> This is the first field
<2TAG> This is the second field
<1TAG> This is the third field
<2TAG> This is the fourth field
<1TAG> This is the fifth field
<2TAG> This is the sixth field
<CTAG> 333333
Is there a way to extract each of these datasets to a separate text file with the unique control ID as filename?
Sample file: Sample.txt
<BTAG> 111111
<1TAG> This is the first field
<2TAG> This is the second field
<3TAG> This is the third field
<4TAG> This is the fourth field
<CTAG> 111111
<BTAG> 222222
<1TAG> This is the first field
<2TAG> This is the second field
<CTAG> 222222
<BTAG> 333333
<1TAG> This is the first field
<2TAG> This is the second field
<1TAG> This is the third field
<2TAG> This is the fourth field
<1TAG> This is the fifth field
<2TAG> This is the sixth field
<CTAG> 333333
Desired output:
Filename 111111.txt
<BTAG> 111111
<1TAG> This is the first field
<2TAG> This is the second field
<3TAG> This is the third field
<4TAG> This is the fourth field
<CTAG> 111111
Filename 222222.txt
<BTAG> 222222
<1TAG> This is the first field
<2TAG> This is the second field
<CTAG> 222222
Filename 333333.txt
<BTAG> 333333
<1TAG> This is the first field
<2TAG> This is the second field
<1TAG> This is the third field
<2TAG> This is the fourth field
<1TAG> This is the fifth field
<2TAG> This is the sixth field
<CTAG> 333333