I am trying to extract last entry from an curl output to only show me the plugin-name and version. Unfortunately miserably failing with my command. Here is the command being used at my end
curl --silent https://jenkins-updates.cloudbees.com/download/plugins/blueocean-github-pipeline/ --ssl-no-revoke | findstr href |Select-String -Pattern "[0-9]/([^<]*)<" |Select-Object -last 1 | ForEach-Object { $_.Matches[0].Groups[1].Value }
Output its giving is blueocean-github-pipeline.hpi">1.25.3
I wish to display only the following blueocean-github-pipeline 1.25.3
and remove "> with a tab in between
How should I go about it?
Thanks in advance
CodePudding user response:
You can use
... | Select-String -Pattern '\d/([^>]*)\.\w ">([^<]*)<' | `
Select-Object -last 1 | `
ForEach-Object { $_.Matches[0].Groups[1].Value " " $_.Matches[0].Groups[2].Value }
Output:
blueocean-github-pipeline 1.25.2
See the regex demo.
Details:
\d/
- a digit and a/
char([^>]*)
- Group 1: any zero or more chars other than a>
char\.
- a dot\w
- one or more word chars">
- a fixed string([^<]*)
- Group 2: any zero or more chars other than a<
char<
- a<
char.
The final result is the concatenation of Group 1 space Group 2.