Remove 3 lines from txt document

I have a txt file which is a report that I download from a web.

The thing is that it contains 3 lines, which change dynamically, but there are always 3 lines and then the rest of the report I need, which has the headers and the information separated by commas.

Here I leave an example screenshot. The white box is what should be deleted, but that information changes dynamically (date and name of the report)

capt01

I tried deleting using “split”, but it didn’t work for me.

I hope you can help me.

Hi @vfaundez

welcome to the UiPath Forum, Based on your statement I assumed your structed data will be always available on 4th line, If so I have developed a xaml file for your requirement so please download the same, try out it

Extracting_Structured_Data.xaml (6.9 KB)
Hope it solves your issue.

Regards
Robinnavinraj S

Hi,

Can you try the following expression?

yourString = System.Text.RegularExpressions.Regex.Replace(yourString,"^.*\n.*\n.*\n","")

Regards,

@vfaundez

You can try this in assign activity.Expression before equals on left of assign and after equals on right of assign

str = System.Text.RegularExpressions.Regex.Replace(str,"(.*\n){3}","")

Here str is the string you have in text file…you can use read text file activity and output can be stored in str

Hope this helps

Cheers

I tried your solutions and none worked.
I tried the regex that they told me and nothing either…

In the screenshot you can see that using its recommendations, it selects all of them and not the first 3 lines.
capt01

I have searched the internet for a solution, but I only find how to remove line breaks and not the first 3 lines…

I attach an example txt

Can you try out my previously attached xaml file

Regards,
Robinnavinraj S

Hi,

Hope the following sample helps you.

 System.Text.RegularExpressions.Regex.Replace(strTxt,"^.*\n.*\n.*\n","")

Sample20230605-1aL.zip (2.9 KB)

Regards,

1 Like

@vfaundez

You should change flavour to c# and also select multiline option…both are not done

Cheers

It didn’t work. If you delete the first 3 lines of the file, but down it only considers around 100 records (line breaks) and the report has more than 7000 records, then I lose more than 90% of the information…

@vfaundez

Try using this

"Contrados," + Str.Split({"Contrados,"},Stringsplitoptions.None)(1)

Cheers

Hi,

How did you check it? If use Messaebox, it may be limitation of Mssagebox.
Can you try the following sample? This remove the first 3 lines then write it to “result.txt”. Can you check it?

Sample20230605-1aLv2.zip (2.7 KB)

Regards,

Sorry everyone, my mistake.

I did not test well a regex that you left and it worked excellent.

System.Text.RegularExpressions.Regex.Replace(yourString,"^.*\n.*\n.*\n","")

Thank you very much to all who offered their help and every day learning more.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.