Parse Text

I need to recursively parse all files in a folder and return the values that are present to the right of the text found within.

The text within is always the same:

ram Files\Queue\textfile.txt

I need to get a result set containing the:

file name searched
textfile.txt values within each found file

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

soostibiConnect With a Mentor Commented:
Try this. You can adjust the pattaren in the first line and the place of the text files to search in the 3rd line.

This will result in a table like this (it even gives you the line number within the text file):
linenumber filename      patternfound            
---------- --------      ------------            
         1 parsetext.txt textfile1.txt            
         2 parsetext.txt textfile2.txt            
         1 pars2text.txt subfolder\textfilesub.txt

In my example the 3rd match shows, that it gives you the subfolder path. If you do not need that, only the filenname, tell me, I'll adjust the code.
$pattern = "Files\\Queue\\([^\.]+\.txt)"

Get-ChildItem c:\yourpathtotxtfiles -Recurse -Filter *.txt | Select-String -Pattern $pattern | %{
    $filename = $_.filename
    $linenumber = $_.linenumber
    $_.matches | %{
        new-object -TypeName PSObject -Property @{
            filename = $filename
            patternfound = $_.groups[1].value
            linenumber = $linenumber

Open in new window

Could you describe your problem more precisely? With some examples.
Felix LevenSenior System and DatabaseadministratorCommented:
find different filetypes example:
Get-ChildItem C:\PSTest\ -Recurse -include *.txt, *.exe, *.ini

Read file:
get-content textfile.txt
CodexK2Author Commented:
Thank you - I know how to recursively look for files within a folder (and search for strings within these files).

What I need help with is searching within each and every file within a given folder for this text:


...and then only returning the value found to the right of 'Files\Queue' the example above the value returned would be:


Ideally the result set will output the name of the file and the values found.

CodexK2Author Commented:
Works like a Champ - thank you very much!!
All Courses

From novice to tech pro — start learning today.