I have an output file with the following content. I want to split it into blocks based on “pattern” and store in a array.
Sample output:
100 pattern
line 1
line 2
line 3
101 pattern
line 4
102 pattern
line 5
line 6
...
Content between nth and (n+1)th occurrence of “pattern” is a block:
Block 1:
100 pattern
line 1
line 2
line 3
Block 2:
101 pattern
line 4
Block 3:
102 pattern
line 5
line 6
Basically I am searching for a pattern across lines and storing the content in between into an array.
Please let me know how do I achieve in perl
Assuming that your pattern are full lines containg the word
pattern(and normal lines do not) and you want array elements to be entire blocks: