question

YonglongYL44Wang-5709 avatar image
0 Votes"
YonglongYL44Wang-5709 asked RichMatheisen-8856 commented

powershell to get one specific colume value from one row

if the output is like this

java 14.59%

i want to get the the second colume (14.59% ) and save in one parameter.
how to do that ?

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

This works (assuming the column separator's a space):

 $string = "java 14.59%"
 ($string -split " ")[1]

If there are multiple spaces (or tabs or other 'whitespace' characters) separating the columns, then this will work:

 $string -replace  "^.+?\s+(.+)$",'$1'

Or even this (if it's always spaces as separators):

 $string.split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[1]


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YonglongYL44Wang-5709 avatar image
0 Votes"
YonglongYL44Wang-5709 answered RichMatheisen-8856 commented
  $string -replace  "^.+?\s+(.+)$",'$1'   is working for me  , thanks you very much.

now , i can get 14.59%. another question is how to remove % form 14.59% ?
what i want is 14.59 .

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

How about this?

 $string -replace  "^.+?\s+(.+)%$",'$1'
0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered RichMatheisen-8856 commented

Hi @YonglongYL44Wang-5709 ,

this should help:

 "14.59%" -Replace "%",""
    
 # or this way:
    
 $b = "14.59%"
 $b.Replace("%","")


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The string in the original question was "java 14.59%".

0 Votes 0 ·