-1

I have a TIBCO bwadmin show application command which gives the output as below.

TIBCO ActiveMatrix BusinessWorks version 6.x.x, hotfix 10, build V145, 2019-03-27

Domain: DOMAIN_NAME

Name                                               Version  AppSpace                       Profile                        Status          Deployment Status (Running/Total)
ApplicationName1.app                                1.1      APPSPACE_NAME                  DEV.substvar                   Running         Deployed          (1/1)
ApplicationName2.app                                1.2      APPSPACE_NAME                  DEV.substvar                   Running         Deployed          (1/1)

powershell output screenshot

I want to parse this output to get the "Version" value for the application "ApplicationName2.app" (i.e: 1.2) and pass it in another command using Powershell. We may have n number of applications, so I should be able to get the Version value for corresponding application. Can anyone please let me know how we can achieve this?

Thanks in advance!

Raj
  • 3
  • 3
  • 1
    For someone (me) not familiar with this command line tool, a lot is left for interpretation with this post. If you captured this output in a variable (`$out`), you could create some search criteria to extract the data you need. For example, `($out | select-string -pattern '\S+\s+(\d+\.\d+)\s+').Matches.Groups[1].Value` potentially works for the sample data. Caveats are that you could have an application name with a space, the output is a single string rather than an array of strings, the application name could have a decimal value. All of them mess up the pattern as it is. – AdminOfThings Jan 14 '20 at 16:44
  • 1
    Alternatively, if the application name always ends with `.app`, then you could do something like `($out | select-string -pattern '\.app\s+(\d+\.\d+)\s+').Matches.Groups[1].Value` – AdminOfThings Jan 14 '20 at 16:46
  • please, format your sample data with code formatting so that line endings are preserved. – Lee_Dailey Jan 14 '20 at 17:19
  • @AdminOfThings, thanks for the reply. I have modified the question now based on the latest findings. The answer you suggested is working fine when there is only one application in the output. Is there a way we can get the Version value based onthe Application name? – Raj Jan 14 '20 at 19:15
  • A simple modification can handle multiple entries: `$out | select-string -pattern '\.app\s+(\d+\.\d+)\s+' | foreach {$_.Matches.Groups[1].Value}`. – AdminOfThings Jan 14 '20 at 19:23

2 Answers2

0

Assuming no spaces in each column. If the columns are always in the same location, see Convert fixed width txt file to CSV / set-content or out-file -append?

whatever.exe | select -Skip 5 | foreach { (-split $_)[1] }


1.1
1.2
js2010
  • 23,033
  • 6
  • 64
  • 66
0

If your output data has no spaces, you can do something like the following, which can be modified if your data delimiters can be predictable:

$apps = (bwadmin show application | Select-Object -Skip 5) -replace '\s+',',' |
    ConvertFrom-Csv -Header 'Name','Version','AppSpace','Profile','Status','Deployment Status','(Running/Total)'
$apps

# Output
Name              : ApplicationName1.app
Version           : 1.1
AppSpace          : APPSPACE_NAME
Profile           : DEV.substvar
Status            : Running
Deployment Status : Deployed
(Running/Total)   : (1/1)

Name              : ApplicationName2.app
Version           : 1.2
AppSpace          : APPSPACE_NAME
Profile           : DEV.substvar
Status            : Running
Deployment Status : Deployed
(Running/Total)   : (1/1)

If you want to list only the application name and version, you can do the following:

$apps | Select-Object Name,Version

#Output
Name                 Version
----                 -------
ApplicationName1.app 1.1
ApplicationName2.app 1.2

If you want to search for an application's version, you can do the following:

$apps | Where Name -eq 'ApplicationName2.app' | Select -Expand Version

#Output
1.2
AdminOfThings
  • 23,946
  • 4
  • 17
  • 27