Search code examples
powershelltext-processingcommand-substitution

How to use powershell to get the next word, in this case it's number, from a specific word in the output


How to use powershell to echo the next word, in this case it's number, from a specific word in the output

For example this command

powershell echo "$(chia wallet show -w standard_wallet | Select-String -Pattern "Spendable:")

Gives this line that has the specific word "Spendable:" from the output

   -Spendable:             0.255502536372 xch (255502536372 mojo)

How do I get only the next word in this line which is 0.255502536372 in this case


Solution

  • You can use a Positive Lookbehind to match for the requested.

    powershell "(chia wallet show -w standard_wallet | Select-String -Pattern '(?<=Spendable:\s+).\.\d+').Matches.Value"
    

    RegEx Demo