Select-String group


i trying read text file powershell use select-string.

when this:

statement date: 04/12/15" | select-string -pattern "statement date: (?<digit>\d{2}[/]\d{2}[/]\d{2})" | select -expand matches | foreach {$_.groups["digit"].value} - works fine. value "04/12/15"

this have:

gc -path $file | select-string -pattern "statement date: (?<digit>\d{2}[/]\d{2}[/]\d{2})" | select -expand matches | foreach {$_.groups["digit"].value} - nothing

thanks help



freddy91761_1


i think need more info in $file because above example seems work if file contains "statement date: 04/12/15"

ps:> set-content c:\temp\testfile "statement date: 04/12/15"

ps:> gc c:\temp\testfilestatement

date: 04/12/15

ps:> gc c:\temp\testfile  | select-string -pattern "statement date: (?<digit>\d{2}[/]\d{2}[/]\d{2})" | select -expand matches | foreach {$_.groups["digit"].value}

04/12/15






Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Domain migration ERR3:7075 Failed to change domain affiliation, hr=8007054a This operation is only allowed for the Primary Domain Controller of the domain

How do a find data in one file, search for it in another file and if not found, write a custom message to another file