Getting Data from Text file

Hello Team, I am having a text file which has data and data is not fixed but the structure is fixed.

I need data from there with the validation below is the screenshot of file for reference also I have attached the file
ATTACH2.txt (1.7 KB) Doc1.docx (32.0 KB)

Please let me know if you have any solution for this

1 Like

Take two variables one for String array ->named Split
Second one string variable -> named Aftersplit
Textoutput->textop

To get the first row set values

Assign -> Split = textop.Split({“AGENT”},Stringsplitoptions.None)
Assign -> Aftersplit = Split(1).ToString
Assign -> Split = Aftersplit.Split({Environment.Newline},Stringsplitoptions.None)
Assign -> Aftersplit = Either Split(0).ToString or Split(1).ToString depending upon the line spacing
Assign -> Split = Aftersplit.Split({" "},Stringsplitoptions.None)
Take an integer variable to store string length, let it be “Length”
Length = Split.length
output values for the first set of rows would be

op1 = Split(1).tostring.trim (First value)
op2 = Split(Length-1).Tostring.Trim (Last value)

To get the first row set values

Assign -> Split = textop.Split({“AGENT”},Stringsplitoptions.None)
Assign -> Aftersplit = Split(1).ToString
Assign -> Split = Aftersplit.Split({“AGENT”},Stringsplitoptions.None)
Assign -> Aftersplit = Split(1).ToString
Assign -> Split = Aftersplit.Split({Environment.Newline},Stringsplitoptions.None)
Assign -> Aftersplit = Either Split(0).ToString or Split(1).ToString depending upon the line spacing
Assign -> Split = Aftersplit.Split({" "},Stringsplitoptions.None)
Take an integer variable to store string length, let it be “Length”
Length = Split.length
output values for the Last set of rows would be

op1 = Split(1).tostring.trim (First value)
op2 = Split(Length-1).Tostring.Trim (Last value)

Please mark as solution if it works for you

Most easy you can solve this by using a regular expression. You will find many posts in this forum or on Interner regarding this.

Cheers

Could you send me xaml file for the same it will be helpfull

Hello Could you please send a xaml file for the same it will be helpfull

Hi @Chirag1991,
you should show more respect to Forum contributors by following the Forum rules

Mainly the rule " Search first"

You would find this very helpful post

Cheers

1 Like

Hi @Chirag1991

May i know the exact output from the below img ?? So that i can move further

Because i am getting the Exact lines in my workflow as shown in the below img :-

image

image

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hello Joska I didn’t mean to offend anyone I have already the regex one but I am looking for split option so I am looking for another option

Hello Pratik I just need 37931439 0000 W0 and 151334 from this file in your second screenshot W0 is missing could you please share me xaml so I can use

Hello Pratik I need 37459194 0100 W0 and151334 from first screen shot in some cases we don’t have W0 so we need to handle that as well please do let me know if you found some solution for the same

Hi @Chirag1991

So what exactly you need ??

If W0 is not present so we have to consider W0 der or not ??

And if “W0” is not present then instead of that what else can come der ??

What output you want when “W0” is not present ??

Bcz the text file you shared in which Second time der is no “W0”

Depending on your answer i have to update the workflow and then i can send working workflow which fulfils your requirement

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi @Chirag1991

If “W0” is Present then Output will be as follows :-

image

If “W0” is not Present then Output will be as follows :-

image

Below is the workflow for the same :-
MainPratik.xaml (13.1 KB)
ATTACH2.txt (1.7 KB)
Doc1.docx (32.0 KB)

If this is not the expected output then answer the above post Questions

If this is the perfect expected output then Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

Hi @Chirag1991

Thank you for the providing a Sample.
Thank you for providing the Output (W0)

Tell us about the Pattern of The text.
Does it always start with “W0”
What is the length of the result you need?
What are the combination of letters in the result?
Is it always present in the text?

The more information you provide the better Pattern and robust solution forum gurus can provide like @Pratik_Wavhal.

As @J0ska linked, take a look at the MegaPost and you will be in a much better place asking for help. :slight_smile:

Cheers

Steve

1 Like

Thanks a Lot it worked as it should be

error.docx (20.4 KB)

Hello Pratik I think we both have different version of uipath due to that one activity could not load in my uipath so could you please provide me screen shot of the same
Thanks

Hello Pratik I need whole line which I have sent you In your code only first and last but it should be all line which has polis and agent number

Hi @Chirag1991

Below is the SS for the Activity that is missing at your end bcz of different UiPath Versions :-

I am having below UiPath Version :-
image

Regex used in Matches Activity as shown below :-

“(?<=AGENT)\s+\n.+”

Properties for matches activity as below :-
image
and “regex” is the output variable of Matches Activity

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi @Chirag1991

Hello Pratik I need whole line which I have sent you In your code only first and last but it should be all line which has polis and agent number

Can you give the exact output here ??

And one more question that will the number of lines of data will be dynamic or constant ??
For eg “REGIO=LEUVEN” have 3 lines of data that we have to extract & “REGIO=CENTR.REGIO” have 1 line of data that we have to extract

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi @Chirag1991

As @Steven_McKeering said just always clear the things in detail so that providing solution gets easier for all of us and so we also wont ask more ques again and again :smile:

Also @Steven_McKeering and all of us are der to give you much better solution always

Thanks @Steven_McKeering u too are my Guru :innocent:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

Hello Pratik I have attached the output what I want from that inputATTACH2 output.txt (244 Bytes)

Please do let me know if you need any more information