Split a string from a table in a txt

youki 1,021 Reputation points
2023-02-06T15:06:50.6133333+00:00

Why doesn't it split/ remove the other two values in front of the searched value?

I only need the value after ttt.

Auto               Fahrrad              Roller                                                                        
------------------ -------------------- --------------------------------------------------------------------------------
HA_123                 			79777   ttt2345                 
HA_123                          79778   ttt4567  



PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,595 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 46,811 Reputation points
    2023-02-06T19:37:37.3833333+00:00

    I think I'd do it differently:

    $regex = "[^\s]+\s+[^\s]+\s+ttt(\d+)"   # Not Whitspace / Whitespace / Not Whitspace / Whitespace ttt digits
    
    $filePath = "C:\Users\zippi\Desktop\PowershellTest"
    $global:Ids = $null
    
    Get-ChildItem $filePath -Filter *.txt -Recurse | 
        ForEach-Object {
            Get-Content $_.FullName |
                ForEach-Object{
                    if($_ -match $regex){
                        $Ids += $matches[1]
                    }
        }
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.