0

I need to extract a string from the following $parse.

 $parse = select-string -path .\xxx.log "Error" -allmatches –simplematch -context 1 

Example of string contain:

 Start : Error : billing 1150116682 not found - exit. Source : /mnt/xxx/roo/foo/aaa/115565841_yyyyy.pdf
=================================================================================================================================================== 

I need extract only Source : /mnt/xxx/roo/foo/aaa/115565841_yyyyy

how can I do it ?

thx

1
  • You can use substring for that. Commented Feb 8, 2017 at 15:12

2 Answers 2

1

Don't use -SimpleMatch because that prevents use of a regular expression, which we can use to extract the needed substring. Here is an example:

$s = "Start : Error : billing 1150116682 not found - exit. Source : /mnt/xxx/roo/foo/aaa/115565841_yyyyy.pdf"
$s | Select-String "Error : .* Source : (.*)" | ForEach-Object {
  $_.Matches[0].Groups[1].Value -replace '\.pdf$', ''
}

The above outputs the string /mnt/xxx/roo/foo/aaa/115565841_yyyyy.

Sign up to request clarification or add additional context in comments.

4 Comments

exclude the .pdf
Thank you for your answers.
I also found in this property what I also look for. All I have to do is to treat her <pre> $parses |foreach { $_.context.Postcontext } </pre>
Thanks! I had to list the versions from a path. $listOfInstalledVersions = Get-ChildItem $path | Select-Object Name | Select-String "funky\.foo-(\d+\.\d+\.\d+\.\d+)" | ForEach-Object { $_.Matches[0].Groups[1].Value }
0

You can do a string split like this:

$array = $parse.split(':') $lastItem = $array[-1]

And then get the item you want from the list. Assuming you know where what you need is.

1 Comment

Thank you for your answers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.