I have a series of data I want to print the data after one match and next different match which comes after the first match for example,
I have
AAA
AAAD
BBB
CCC
AAA
AAADD
Want the data between AAAD and AAA.
There's AAA in the 1st line too but I want it to catch AAAD first and then print the data till it catches the next match which is AAA on line 5
output needed :
AAAD
BBB
CCC
AAA
I tried
perl -lne 'print if /AAAD/../AAA/' p
it gave
AAAD
AAADD
it's giving exact matches and printing them rather than giving lines in between.
As noted in comments, you need to use the
...range operator to prevent matching on the same line. Like so:From the documentation:
This code, with the regexes you provided, allows partial matches. If this is not what you want, you can use anchors to enforce only complete matches. E.g.: