Search Keywords in files

Hi Team,

I have a scenario in which I have a bunch of comma separated keywords in a notepad file. Then I have a folder in which there is few files which contain random phrases in it.

The process is to
read through the keyword notepad file, and
If the keyword is found in any of the files present in the folder, the bot should display the keyword that is found in the file, the phrase line and the filename.

Please do help me with this.

@Techno1,

Check this post, instead of the .txt file you can use it for .csv

Hi, Thanks for the reply @sarathi125 .

In my project I have like hundreds of keywords which I’m saving as a data table variable.
Could you help me how to pass this variable into a regex expression or VB expression to check if these keywords are found in the files in the folder.

Hi @Techno1

having in array would be easy so you can convert datatable to array (hope you have only one column) dt.AsEnumerable.Select(function(x) x(“columnname”).ToString).ToArray

And use as described in this post

If you are having multiple columns then create multiple arrays or use a for each loop and then check

Cheers

Hi @Anil_G ,Thank you for the reply.

Is this going to work with multiple columns?
In my case, i have multiple columns, each keyword is considered as a column.

Hi @Techno1

It works…Change the column names accordingly and create arrays out of it and use them. If you want all in one array then combine all arrays and use

cheers

Suppose i have these keywords as CSV given below.

and the resulting data table in this format given below.

How to convert these into arrays.

Hi @Techno1

read csv with add headers checked into datatable(dt)

if in Excel
Read excel into datatable(dt) using Read range and check the property add headers then

(From dc In dt.Columns.Cast(Of System.Data.DataColumn) Select dc.ColumnName).ToArray() is your array

if a text file then read text into string(str) then

str.Split(","c) is your array

Hope this answers your question

cheers

Hi @Techno1

If your issue is resolved can you please close it with marking solution, so that it helps others as well

cheers