Parsing A Report

R

raven

I have a system report that some of you may be familiar with. It is
the output from the print_manifest command on an HP-UX system with
ignite installed. There are divisions in the text file that I am
trying to break up, but feel like I am going about wrong. I am trying
to extract the block of text within 'Installed Software' up to the
next major heading. Can someone check my work and comment? Thanks. See
below:

Report:

Installed Software

Your system was installed with HP-UX version B.11.11.

Your system has the following software products installed and
configured on the system disk drive(s).

Product Revision Description
B2491BA B.11.11 MirrorDisk/UX
B3701AA C.03.25.00 HP GlancePlus/UX Pak for s800
11i
B3913DB C.03.30.01 HP aC++ Compiler (S800)
B5725AA B.3.3.116 HP-UX Installation Utilities
(Ignite-UX)
B6834AA B.01.00 HP-UX Security Patch Check Tool
B9901AA A.03.05 HP IPFilter 3.5alpha5
BUNDLE11i B.11.11.0102.2 Required Patch Bundle for HP-UX
11i, February 2001
CDE-English B.11.11 English CDE Environment
FDDI-00 B.11.11.01 PCI FDDI;Supptd
HW=A3739A/A3739B;SW=J3626AA
FibrChanl-00 B.11.11.06 PCI/HSC FibreChannel;Supptd
HW=A6684A,A6685A,A5158A
GigEther-00 B.11.11.14 PCI/HSC GigEther;Supptd
HW=A4926A/A4929A/A4924A/A4925A;SW=J1642AA
HPUX11i-OE B.11.11.0106 HP-UX 11i Operating Environment
Component
HPUXBase64 B.11.11 HP-UX 64-bit Base OS
HPUXBaseAux B.11.11.0106 HP-UX Base OS Auxiliary
HWEnable11i B.11.11.0106.8 Hardware Enablement Patches for
HP-UX 11i, June 2001
Ignite-UX-11-11 B.3.3.116 HP-UX Installation Utilities
for Installing 11.11 Systems
J4189-11001B E.10.18 Hewlett-Packard JetDirect
Printer Installer for Unix
OnlineDiag B.11.11.03.08 HPUX 11.11 Support Tools
Bundle, Jun 2001
RAID-00 B.11.11.01 PCI RAID; Supptd HW=A5856A


LVM File System Configuration

This system is configured with Logical Volume Manager (LVM) file
systems.
Refer to the File System layout section for information on the LVM
layout.


JFS File System Configuration

This system is configured with a Journaled File System (referred
to
as either JFS or VXFS). Refer to the File System layout section
for
information on JFS/VXFS file systems.


Code:

#!/usr/contrib/bin/perl -w

open SOFTWARE, "system.txt" or die "Cannot open file!";

$flag = 0;
while (<SOFTWARE>) {
if (/^Installed Software/) {
$flag = 1;
next;
}
if ($flag) {
last if (/^\w+/);
# Where we do the work.
}
}
 
T

Tore Aursand

I have a system report that some of you may be familiar with. It is
the output from the print_manifest command on an HP-UX system with
ignite installed. There are divisions in the text file that I am
trying to break up, but feel like I am going about wrong. I am trying
to extract the block of text within 'Installed Software' up to the
next major heading. Can someone check my work and comment? Thanks. See
below:
[...]

Actually, it's very easy. I won't provide you with any code for now, only
the "way of thinking" (although I might be wrong).

Start collecting data after you've recognized that 'Installed Software' is
the beginning string on the line.

Stop collecting data when you reach the next string that begins at the
beginning of the line (hope you'll understand what I mean with that), as
all the lines you want seem to be indented.

However, I wouldn't have done it this way. :) I would have looped
through the lines and started collection data as soon as I reach something
I can count as 3 columns (eventually, and in addition, after having met
that 'Product', 'Revision', 'Description' line).

Something like that (although I have no idea if it works);

while ( <DATA> ) {
chomp;
my @cols = split( /\s+/ );
if ( $cols[0] =~ m,\d+, ) {
## Yeah, I want those lines with numbers in the first column!
print join( "\t", @cols );
}
}

I don't know if this works; I'm watching soccer and have had a few beer,
so... :)
$flag = 0;

One thing I've learnt during my "Perl period" is that you never should use
any "flags" in your code. If you have to, you most probably do something
wrong. Can't really explain it, though...


--
Tore Aursand <[email protected]>

"You know the world is going crazy when the best rapper is white, the best
golfer is black, France is accusing US of arrogance and Germany doesn't
want to go to war."
 
J

John W. Krahn

raven said:
I have a system report that some of you may be familiar with. It is
the output from the print_manifest command on an HP-UX system with
ignite installed. There are divisions in the text file that I am
trying to break up, but feel like I am going about wrong. I am trying
to extract the block of text within 'Installed Software' up to the
next major heading. Can someone check my work and comment? Thanks. See
below:

Report:

Installed Software

Your system was installed with HP-UX version B.11.11.

Your system has the following software products installed and
configured on the system disk drive(s).

Product Revision Description
B2491BA B.11.11 MirrorDisk/UX
B3701AA C.03.25.00 HP GlancePlus/UX Pak for s800 11i

[snip]

OnlineDiag B.11.11.03.08 HPUX 11.11 Support Tools Bundle, Jun 2001
RAID-00 B.11.11.01 PCI RAID; Supptd HW=A5856A

LVM File System Configuration

[snip]


#!/usr/contrib/bin/perl -w

open SOFTWARE, "system.txt" or die "Cannot open file!";

You should include the $! variable in the error message to find out why
the open failed and you might want to include the file name as well.
You could probably run the print_manifest command through a pipe and
avoid using a report file if you want.

$flag = 0;
while (<SOFTWARE>) {
if (/^Installed Software/) {
$flag = 1;
next;
}
if ($flag) {
last if (/^\w+/);
# Where we do the work.
}
}

You can use the range operator in scalar context to get the lines you
want

while ( <SOFTWARE> ) {
chomp;
if ( /^Installed Software/ .. /^\S/ ) {
# Where we do the work.
my ( $prod, $rev, $desc ) = split ' ', $_, 3;
next unless $rev =~ /\d/;
}
}



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top