<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to read desired lines from a text file ? in Product Forum</title>
    <link>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56598#M10755</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a text file. I want to perform following steps -&lt;BR /&gt;1. Find "agrawal" in the text file.&lt;BR /&gt;2. Wherever I have "agrawal", I want to read the line which is just above it.&lt;BR /&gt;3. Again, press "Find Next" for "agrawal" and read the line just above it. Keep doing this till search has finished.&lt;BR /&gt;&lt;BR /&gt;Below is the sample text file.&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26373.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26499iD9F4121D3A805F92/image-size/large?v=v2&amp;amp;px=999" role="button" title="26373.png" alt="26373.png" /&gt;&lt;/span&gt;&lt;BR /&gt;Please suggest.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance !!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Swati Agrawal&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
    <pubDate>Thu, 21 Apr 2022 13:41:00 GMT</pubDate>
    <dc:creator>SwatiAgrawal</dc:creator>
    <dc:date>2022-04-21T13:41:00Z</dc:date>
    <item>
      <title>How to read desired lines from a text file ?</title>
      <link>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56598#M10755</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a text file. I want to perform following steps -&lt;BR /&gt;1. Find "agrawal" in the text file.&lt;BR /&gt;2. Wherever I have "agrawal", I want to read the line which is just above it.&lt;BR /&gt;3. Again, press "Find Next" for "agrawal" and read the line just above it. Keep doing this till search has finished.&lt;BR /&gt;&lt;BR /&gt;Below is the sample text file.&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26373.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26499iD9F4121D3A805F92/image-size/large?v=v2&amp;amp;px=999" role="button" title="26373.png" alt="26373.png" /&gt;&lt;/span&gt;&lt;BR /&gt;Please suggest.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance !!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Swati Agrawal&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Apr 2022 13:41:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56598#M10755</guid>
      <dc:creator>SwatiAgrawal</dc:creator>
      <dc:date>2022-04-21T13:41:00Z</dc:date>
    </item>
    <item>
      <title>RE: How to read desired lines from a text file ?</title>
      <link>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56599#M10756</link>
      <description>Hi &lt;A class="user-content-mention" data-sign="@" data-contactkey="ee428c3f-756e-471c-ab71-d0fe7a9ef951" data-tag-text="@Swati Agrawal" href="https://community.blueprism.com/network/profile?UserKey=ee428c3f-756e-471c-ab71-d0fe7a9ef951" data-itemmentionkey="3b98ca35-a9f5-4a35-9b8f-db8af9a63491"&gt;@Swati Agrawal&lt;/A&gt;,&lt;BR /&gt;&lt;BR /&gt;There are a few ways you could do this. You don't mention is you're trying to do this via UI automation or not though. The first solution that comes to my mind is to use the &lt;STRONG&gt;Utility - File Management&lt;/STRONG&gt; VBO​. There's an action called &lt;EM&gt;&lt;STRONG&gt;Read Lines from File&lt;/STRONG&gt;&lt;/EM&gt;. It will return a Collection of all the lines in the file. Then you could loop through the Collection looking for the lines that match your criteria. You would want to use a temporary data item to store each line as you go though so you have an easy way to recall the previous line when you match &lt;STRONG&gt;agrawal&lt;/STRONG&gt;.&lt;BR /&gt;&lt;BR /&gt;Does that make sense?&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26363.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26494i8C43DB8ED91F6378/image-size/large?v=v2&amp;amp;px=999" role="button" title="26363.png" alt="26363.png" /&gt;&lt;/span&gt;&lt;BR /&gt;If you were going to try and do this via UI automation, the same general principal would apply. As I mentioned there are multiple ways to do this. You could even drop into a Code stage in a VBO and use Linq or other options like OLEDB for pulling out the information.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Eric Wilson&lt;BR /&gt;Director, Integrations and Enablement&lt;BR /&gt;Blue Prism Digital Exchange&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Apr 2022 14:17:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56599#M10756</guid>
      <dc:creator>ewilson</dc:creator>
      <dc:date>2022-04-21T14:17:00Z</dc:date>
    </item>
    <item>
      <title>RE: How to read desired lines from a text file ?</title>
      <link>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56600#M10757</link>
      <description>Hi &lt;A class="user-content-mention" data-sign="@" data-contactkey="ee428c3f-756e-471c-ab71-d0fe7a9ef951" data-tag-text="@Swati Agrawal" href="https://community.blueprism.com/network/profile?UserKey=ee428c3f-756e-471c-ab71-d0fe7a9ef951" data-itemmentionkey="6b0d4d06-f51a-4c3a-989f-e7bc96657f0e"&gt;@Swati Agrawal&lt;/A&gt;,&lt;BR /&gt;&lt;BR /&gt;As mentioned by &lt;a href="https://community.blueprism.com/t5/user/viewprofilepage/user-id/833"&gt;@ewilson&lt;/a&gt;, the best way would be to use Utility File Management and applying the logic using calculation stages. Otherwise, you can use below options as well to perform the same task:&lt;BR /&gt;&lt;BR /&gt;1) Exporting data in Excel and then utilizing 'Find Text' functionality to identify the cell reference. Post identification of cell reference, you can move the cell reference by one cell up and you can get the data.&lt;BR /&gt;2) Using code stage if you want to perform the operation really fast and making it a generic code.&lt;BR /&gt;3) Using LINQ or OLEDB​​&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;Manpreet Kaur&lt;BR /&gt;Manager&lt;BR /&gt;Deloitte&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Apr 2022 17:48:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56600#M10757</guid>
      <dc:creator>ManpreetKaur1</dc:creator>
      <dc:date>2022-04-22T17:48:00Z</dc:date>
    </item>
    <item>
      <title>RE: How to read desired lines from a text file ?</title>
      <link>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56601#M10758</link>
      <description>&lt;P&gt;Hi Swati,&lt;BR /&gt;&lt;BR /&gt;For your desired use case, I have created a code stage using LINQ and basic iterations that you can probably use. So first create a new business object and add the following '&lt;STRONG&gt;Namespace Imports&lt;/STRONG&gt;', '&lt;STRONG&gt;External References&lt;/STRONG&gt;' and '&lt;STRONG&gt;Language&lt;/STRONG&gt;' setting under the '&lt;STRONG&gt;Code Options&lt;/STRONG&gt;' tab of your page description stage in '&lt;STRONG&gt;Initialise&lt;/STRONG&gt;' action page:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26366.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26497iCC8A0261BF79CA21/image-size/large?v=v2&amp;amp;px=999" role="button" title="26366.png" alt="26366.png" /&gt;&lt;/span&gt;&lt;BR /&gt;External References: &lt;CODE&gt;System.Data.dll,&amp;nbsp;System.Drawing.dll, System.Data.DataSetExtensions.dll, System.Core.dll,.System.Xml.dll&lt;/CODE&gt;&lt;BR /&gt;Namespace Imports: &lt;CODE&gt;System, System.Data, System.Drawing, System.Data.DataSetExtensions, System.LINQ, System.Collections.Generic, System.IO&lt;/CODE&gt;&lt;BR /&gt;Language: &lt;CODE&gt;Visual Basic&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;Now, you can create a new action page called as '&lt;STRONG&gt;Get Previous and Subsequent Values&lt;/STRONG&gt;' with the following input parameters:&lt;BR /&gt;&lt;BR /&gt;- &lt;STRONG&gt;File Path (Text)&lt;/STRONG&gt;: The input file path of the text file where the operation needs to be performed.&lt;BR /&gt;- &lt;STRONG&gt;Search Text (Text)&lt;/STRONG&gt;: The keyword text to be used for search operation.&lt;BR /&gt;- &lt;STRONG&gt;Previous Text Threshold (Number)&lt;/STRONG&gt;: The starting index of the line relative to the line consisting of the keyword for which the previous text that needs to be grabbed in every continuation.&lt;BR /&gt;- &lt;STRONG&gt;Previous Text Limit (Number)&lt;/STRONG&gt;: The ending index of the line relative to the line consisting of the keyword for which the previous text that needs to be grabbed in every continuation.&lt;BR /&gt;- &lt;STRONG&gt;Subsequent Text Threshold (Number)&lt;/STRONG&gt;: The starting index of the line relative to the line consisting of the keyword for which the subsequent text that needs to be grabbed in every continuation.&lt;BR /&gt;- &lt;STRONG&gt;Subsequent Text Limit (Number)&lt;/STRONG&gt;: The ending index of the line relative to the line consisting of Subsequent Text Threshold for which the subsequent text that needs to be grabbed in every continuation.&lt;BR /&gt;&lt;BR /&gt;Also, add an output parameter of type collection which should be an undefined collection. In my example, I have named it as '&lt;STRONG&gt;Lines&lt;/STRONG&gt;' as shown below:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26367.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26501i40B1F141D3895FF4/image-size/large?v=v2&amp;amp;px=999" role="button" title="26367.png" alt="26367.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Add a code stage and map the input and output parameters as shown below:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26368.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26502i39EDA4AC372A27CB/image-size/large?v=v2&amp;amp;px=999" role="button" title="26368.png" alt="26368.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Add the following code:&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Initialize Local Variables&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Dim previousText As String&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;Dim subsequentText As String&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Read Input Text File&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Dim fileContents = File.ReadAllLines(File_Path)&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Get List Of Macthing Indices With Search Word&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Dim matchingIndices= fileContents.Select(Function(x,i) i).Where(Function(i) fileContents(i).ToString.Contains(Search_Text))&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Generate Output Collection Schema&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Lines.Columns.Add("Line Number", GetType(Integer))&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;Lines.Columns.Add("Previous Text", GetType(String))&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;Lines.Columns.Add("Subsequent Text", GetType(String))&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Iterate Through Each Item For Matching Indices&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Dim row As DataRow&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;For Each item In matchingIndices&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;subsequentText = ""&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;previousText = ""&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;row = Lines.NewRow&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Add Matching Line Number Value&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;row("Line Number") = item&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Get Previous &amp;amp; Subsequent Text Values&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Try&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;For i = Previous_Text_Limit To Previous_Text_Threshold + Previous_Text_Limit&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;If previousText = "" Then&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;previousText = fileContents(item + 1 - i)&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Else&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;previousText = previousText + Environment.NewLine + fileContents(item + 1 - i)&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;End If&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Next&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;For i = Subsequent_Text_Limit To Subsequent_Text_Limit + Subsequent_Text_Threshold&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;If subsequentText = "" Then&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;subsequentText = fileContents(item + i)&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Else&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;subsequentText = subsequentText + Environment.NewLine + fileContents(item + i)&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;End If&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Next&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Catch ex As Exception&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;End Try&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Add Previous Text &amp;amp; Subsequent Text As Calculated&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;row("Previous Text") = previousText&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE&gt;row("Subsequent Text") = subsequentText&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;' Add New Row To Output Collection&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Lines.Rows.Add(row)&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;Next&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now you can test the same with sample input file which in my case looks like this:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26369.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26500iEB59612BAFFA9F0A/image-size/large?v=v2&amp;amp;px=999" role="button" title="26369.png" alt="26369.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;For the given input parameters:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26370.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26503iBCCDB1CC4BD5E949/image-size/large?v=v2&amp;amp;px=999" role="button" title="26370.png" alt="26370.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Following results are generated:&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="26371.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/26504i93F3A6B6E1B14F32/image-size/large?v=v2&amp;amp;px=999" role="button" title="26371.png" alt="26371.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------&lt;BR /&gt;----------------------------------&lt;BR /&gt;Hope it helps you out and if my solution resolves your query, then please mark it as the 'Best Answer' so that the others members in the community having similar problem statement can track the answer easily in future&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Devneet Mohanty&lt;BR /&gt;Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,&lt;BR /&gt;Wonderbotz India Pvt. Ltd.&lt;BR /&gt;Blue Prism Community MVP | Blue Prism 7x Certified Professional&lt;BR /&gt;Website: &lt;A href="https://devneet.github.io/" target="test_blank"&gt;https://devneet.github.io/&lt;/A&gt;&lt;BR /&gt;Email: devneetmohanty07@gmail.com&lt;BR /&gt;&lt;BR /&gt;----------------------------------&lt;BR /&gt;------------------------------&lt;BR /&gt;</description>
      <pubDate>Sat, 23 Apr 2022 00:59:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/How-to-read-desired-lines-from-a-text-file/m-p/56601#M10758</guid>
      <dc:creator>devneetmohanty07</dc:creator>
      <dc:date>2022-04-23T00:59:00Z</dc:date>
    </item>
  </channel>
</rss>

