powershell to get one specific colume value from one row

Yonglong YL44 Wang 61 Reputation points
2021-10-21T02:41:40.113+00:00

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 for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2021-10-21T19:56:11.047+00:00

    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]
    
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Yonglong YL44 Wang 61 Reputation points
    2021-10-25T07:48:51.73+00:00
     $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 .


  2. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-10-25T16:54:11.26+00:00

    Hi @Yonglong YL44 Wang ,

    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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.