Extract from Text file

Team,
Putty_Sample_Fail.txt (12.4 KB)

From above file i need to extract below information -

ERR : Error Reading Detail Record Number <328>.
ERR : No Valid Institution for the specified Logo :
ERR : BAD Input file <09272021.csv> renamed to <09272021.csv.20210927.BAD>.
ERR : END_ERROR
ERR : Error Reading Detail Record Number <328>.
ERR : No Valid Institution for the specified Logo :
ERR : BAD Input file <09272021.csv> renamed to <09272021.csv.20210927.BAD>.
ERR : END_ERROR

NOTE - We need to extract all lines which consists of ERR.
It is dynamic in every scenario For eg in attach files there are 8 lines which consists ERR and for other files it may be 3,4,5 etc

Any suggestions ?

Hi @prerna.gupta,

Read text file and use Matches activity with following expression:

ERR\s+.*$

OR

System.Text.RegularExpressions.Regex.Matches(InputText,β€œERR\s+.*$”)

Hope it helps.

This is not working,

Im using System.Text.RegularExpressions.Regex.Matches(YourString,β€œ(?<=ERR\s*:\s)\S.*”),
but this expression only fetches 4 lines of Error in every text file.

Requirement is to fetch every line which consists ERR (which will dynamic)

Hi @prerna.gupta ,

It works here.

Print the text and check before using regex. May be variable is not capturing the whole text.

1 Like


Howare you using it ?

@prerna.gupta

Please try this

System.Text.RegularExpressions.Regex.Matches(str,"(?=\bERR\b).*")

image

cheers

Hi @prerna.gupta,

Try this. It works.

System.Text.RegularExpressions.Regex.Matches(yourText,β€œERR(\s+)[:].*\n”)

Hope it helps.

Hey @prerna.gupta ,
Try this

String.Join( Environment.NewLine,System.Text.RegularExpressions.Regex.Matches( textString,"ERR\s+.*",System.Text.RegularExpressions.RegexOptions.Multiline).Cast(Of System.Text.RegularExpressions.Match).Select(Function(m) m.Value).toarray())

Output :
image

Regards,

HI,

Hope the following sample helps you.

mc = System.Text.RegularExpressions.Regex.Matches(strData,"\bERR\s.*")

Sample20230407-7L.zip (5.4 KB)

Regards,

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