Split a string from a table in a txt

youki 996 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,089 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,096 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