[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

How to parse a text starting with a flag till another special flag?

How can I parse this in Perl?

AA: something in here
and it continues in the next 
and the third
and the n number of lines till the next flag
BB: some new text is here
CC: some other text is also here

Open in new window


This text can also be in this format:

BB: some new text is here
AA: something in here
and it continues in the next 
and the third
and the n number of lines till the next flag
CC: some other text is also here

Open in new window


AA: BB: CC: are the flags.

The expected output is:
something in here
and it continues in the next 
and the third
and the n number of lines till the next flag

Open in new window



The idea for this can be:

Parse everything that starts with AA: till (BB: or CC:)

How can I do that in Perl?

Thanks,
0
Tolgar
Asked:
Tolgar
1 Solution
 
ozoCommented:
while( <DATA> ){
    print if s/^\s*AA:\s*// .. s/\s*(BB|CC):.*//s;
}
__DATA__
    AA: something in here
and it continues in the next
and the third
and the n number of lines till the next flag
    BB: some new text is here
    CC: some other text is also here
0
 
TolgarAuthor Commented:
If this is my original code: (The more complex form of this question is in ID: 27388059)

/^C(S|omments):\s*(.*\n)/ && push(@CS, $2) && goto CHECK;

Open in new window


Can I change it like this with your code in stead of new line character:

/^C(S|omments):\s*(\s*// .. s/\s*(RR|CR|Mail sent to):.*)/ && push(@CS, $2) && goto CHECK;

Open in new window


The thing that I wanna parse is in these formats:

CS:  some text in here
and continues in here
RR:something in here
CR: something in here

Mail sent to: some other thing

Open in new window



or

RR:something in here
CS:  some text in here
and continues in here
CR: something in here


Mail sent to: some other thing

Open in new window


or

RR:something in here
CR: something in here
CS:  some text in here
and continues in here

Mail sent to: some other thing

Open in new window




The part that I wanna capture is:
sometext in here
and continues in here

Open in new window


Do you think it is ok?

Thanks,

0
 
Suhas .QA ManagerCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now