0

I have a script that gives the below output:

WVER0010I: Copyright (c) IBM Corporation 2002, 2012; All rights reserved.
WVER0012I: VersionInfo reporter version 1.15.1.48, dated 2/8/12

--------------------------------------------------------------------------------
IBM WebSphere Product Installation Status Report
--------------------------------------------------------------------------------

Report at date and time September 23, 2020 2:00:11 PM IST

Installation
--------------------------------------------------------------------------------
Product Directory        /ihs/IBM/HTTPServer
Version Directory        /ihs/IBM/HTTPServer/properties/version
DTD Directory            /ihs/IBM/HTTPServer/properties/version/dtd
Log Directory            /var/ibm/InstallationManager/logs

Product List
--------------------------------------------------------------------------------
IHS                      installed

Installed Product
--------------------------------------------------------------------------------
Name                  IBM HTTP Server for WebSphere Application Server
Version               8.5.5.10
ID                    IHS
Build Level           cf101629.01
Build Date            7/21/16
Package               com.ibm.websphere.IHS.v85_8.5.5010.20160721_0036
Architecture          x86-64 (64 bit)
Installed Features    IBM HTTP Server 64-bit with Java, Version 6
                      Core runtime

--------------------------------------------------------------------------------
End Installation Status Report
--------------------------------------------------------------------------------

I need to get the version on al flavors of OS like Aix, Linux and Solaris

With the below command I'm getting the desired output:

sh /ihs/IBM/HTTPServer/bin/versionInfo.sh | grep -A 1 WebSphere | tail -n 1 | awk '{print $NF}'

Output: 8.5.5.10

However, when the script output changes slightly like below the same command does not get me the version.

WVER0010I: Copyright (c) IBM Corporation 2002, 2005, 2008; All rights reserved.
WVER0012I: VersionInfo reporter version 1.15.5.1, dated 6/15/11

--------------------------------------------------------------------------------
IBM WebSphere Application Server Product Installation Status Report
--------------------------------------------------------------------------------

Report at date and time September 23, 2020 1:54:10 PM GMT+05:30

Installation
--------------------------------------------------------------------------------
Product Directory        /ihs/IBM/HTTPServer
Version Directory        /ihs/IBM/HTTPServer/properties/version
DTD Directory            /ihs/IBM/HTTPServer/properties/version/dtd
Log Directory            /ihs/IBM/HTTPServer/logs
Backup Directory         /ihs/IBM/HTTPServer/properties/version/nif/backup
TMP Directory            /tmp

Product List
--------------------------------------------------------------------------------
IHS                      installed

Installed Product
--------------------------------------------------------------------------------
Name                     IBM HTTP Server
Version                  7.0.0.19
ID                       IHS
Build Level              cf191132.09
Build Date               8/13/11
Architecture             Intel (32 bit)

--------------------------------------------------------------------------------
End Installation Status Report
--------------------------------------------------------------------------------

Output:

--------------------------------------------------------------------

However, the desired output is:

7.0.0.19

I 'm expecting the same command to give the version number for both the output above.

Note: I guess if we can search for the the line below the line starting with "Name" followed by <whitespaces> and then followed by "IBM HTTP Server" then we will get the version. However, I'm not able to get grep to get me the desired out.

Can you please suggest ?

2 Answers 2

4

I would suggest an awk-based solution if that tool is available to you:

awk '/^Installed Product/{f=1} f && $1=="Version" {print $2; f=0}'

will set a flag f once the "Installed Product" header was found, and (only) then look for a line starting with "Version". It will print the second of the whitespace-separated fields of that line, which is the version. As a safety measure, it will at the same time reset the flag to ensure no later occurence of a "Version" line generates false output.

You can use it as

sh /ihs/IBM/HTTPServer/bin/versionInfo.sh | awk '/^Installed Product/{f=1} f && $1=="Version" {print $2; f=0}'
3

Based on your example input, you are simply searching for the stretch of numbers and . that comes after the word Version on lines where Version is the first word of the line and where it is followed by whitespace and then a number. If you have GNU grep, you can simply do:

sh /ihs/IBM/HTTPServer/bin/versionInfo.sh | grep -oP '^Version\s+\K\d.*'

If you don't have GNU grep, you can use:

sh /ihs/IBM/HTTPServer/bin/versionInfo.sh | sed -n 's/^Version[ \t]*\([0-9]\)/\1/p'

Or, perhaps more legibly:

sh /ihs/IBM/HTTPServer/bin/versionInfo.sh | 
    awk '/^Version  *[0-9]/{print $2}' 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.