web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Extract all lines from...
Power Automate
Answered

Extract all lines from a body of an email after I find a certain line

(1) ShareShare
ReportReport
Posted on by 27

Hello,  Sorry but this is one more email body extraction question from a newb.

I want to extract everything out of the body of an email starting at a certain line.  

When I hit the line I am looking for, I want that line and every line after that so I can save it to text file on my network.

I've got all lines in an array but I don't know how to find the ones I am looking for.

 

I included a screen print that shows what I have so far to identify the correct emails and parse the email body into an array.  All of this works up to this point.

 

Starting when I see the line that begins with "Ack/997 FOR RGA"

  I want everything in blue.

My end of my array looks like this:

 

"",
"ZjQcmQRYFpfptBannerEnd",
"",
"BODY OF THE E-MAIL:",
"",
"===========================================",
"",
"Ack/997 FOR RGA 667000176",
"",
" ",
"",
"ISA*00*          *00*          *14*056671711some  *ZZ*mycomp        *230906*1801*^*00406*001059296*0*P*>…",
"",
"GS*FA*056671711some*mycomp*20230906*1801*813043*X*004060…",
"",
"ST*997*313044…",
"",
"AK1*AN*667000176…",
"",
"AK2*180*668000176…",
"",
"AK5*A…",
"",
"AK9*A*1*1*1…",
"",
"SE*6*313044…",
"",
"GE*1*813043…",
"",
"IEA*1*001059296…"
]

 

 

Capture.PNG
Categories:
  • trice602 Profile Picture
    16,679 Super User 2026 Season 2 on at

    Hi @EDIGuy ,

     

    Here's one way to do this and in my test it works well for me.  From here, you can clean up the text, etc - I didn't spend anytime on that part, but just wanted to show how I can capture the text in the starting position requested.

     

    trice602_0-1694138030268.png

     

    In this example, I use the Action Fin text position from the html to text action so I can find the starting position of Ack/997 FOR...

     

    trice602_1-1694138122216.png

     

    Then from here I use a compose substring to get the text at the start position from the previous step.  Again, from here, you can create your new lines, remove quotes, etc, etc but it does successfully capture the data in blue.

     

    substring(body('Html_to_text'),body('Find_text_position'))
     
    trice602_2-1694138218330.png

     

     

  • EDI_Manager Profile Picture
    27 on at

    Is that text position the character count of where the phase is? I think it set to 127 or 217 or something.   How do I use that to extract that line and all lines after that?  There are only about 20 lines in the email.  I tried lots of things to try to loop from that line to the end but I am not very experienced yet.

     

  • trice602 Profile Picture
    16,679 Super User 2026 Season 2 on at

    Hi @EDIGuy ,

     

    The character position is dynamic and will start wherever that is in the email.  My expression captures all lines starting at the phrase to the end so, 20 lines, 50 lines, etc .. doesn't make a difference and you don't loop through lines you are capturing the entire body of the email as a single output.

     

     

  • EDI_Manager Profile Picture
    27 on at

    Thank you for your help.  When I run this I am getting the entire body of the email.  Can't tell if I missed something???   

    This: substring(body('Html_to_text'),body('Find_text_position'))  should return everthing after the search phrase?

  • trice602 Profile Picture
    16,679 Super User 2026 Season 2 on at

    Hi @EDIGuy ,

     

    Correct.  Starts at Ack/997 FOR RGA 667000176 and capture that plus everything below it in the body of the email.  

     

     

     

     

  • Verified answer
    EDI_Manager Profile Picture
    27 on at

    K thank you.  I'll give it a try again.  Maybe that phrase is in the email body twice or something?

    Again,  THank you very much for your help!

  • Verified answer
    trice602 Profile Picture
    16,679 Super User 2026 Season 2 on at

    You are welcome @EDIGuy  - always glad to help.  The substring expression is going to find the first one, if there are more than two, but yeah, check it out and mark as a solution if this works for you so others can find this flow too!

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 425

#2
11manish Profile Picture

11manish 323 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard