Hi,
i have a file with different types of records in it in following format:
I need to extract all the records that have var2 = 3 into
different file and delte them from existing one. I know that every record that has var2 = 3 is 11 lines long.
So every time i find var2 = 3 i need to get one line before (record header) and next 10 lines into new file, and delete them from original file.
Please help :)
<Rec 1>
var2 = 5
some text
some text
some text
some text
</Rec 1>
<rec 2>
var2 = 3
some text
some text
some text
some text
some text
some text
some text
some text
</Rec 2>
<Rec 3>
var2 = 7
some text
some text
some text
some text
some text
some text
</Rec 3>
<rec 4>
var2 = 3
some text
some text
some text
some text
some text
some text
some text
some text
</Rec 4>
so output from this data would be
file_1
<Rec 1>
var2 = 5
some text
some text
some text
some text
</Rec 1>
<Rec 3>
var2 = 7
some text
some text
some text
some text
some text
some text
</Rec 3>
file_2
<rec 2>
var2 = 3
some text
some text
some text
some text
some text
some text
some text
some text
</Rec 2>
<rec 4>
var2 = 3
some text
some text
some text
some text
some text
some text
some text
some text
</Rec 4>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.