- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: from horizon text format into vertical text fo...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 11:07 AM
тАО09-27-2009 11:07 AM
Re: from horizon text format into vertical text format
input as attach sample file.
1. extract line 17 to line 57
2. reformat & convert into following output
slot1/0:0
slot1/1:0
.
.
slot1/total:0
slot4/0:0
.
.
slot4/25:4300
.
slot4/27:4300
.
slot4/total:17000
.
.
slot9/16:144000000
.
.
slot9/19:67000000
slot9/total:423000000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 12:29 PM
тАО09-27-2009 12:29 PM
Re: from horizon text format into vertical text format
That's just a crazy restriction to get yo into trouble later.
What you really want is to recognize the report pattern, ending in 'total' like my example already did.
It simply ignores the noise before ( $. < 17) and after ( $. > 57 )
I failed to see the decimal value requirement, and so it seems did Jim.
The \d+ use looks for charactes 0 thru 9, but here we need to use [0-9.]+ to add the .
One possible solution then becomes:
------------------ reformat.pl ----
while (<>) {
push @tag,split if /^\s*\d+\s+/;
if (/^(sl.*):(.*)/) {
$nam=$1;
$_ = $2;
push @val,split;
#debug print " -- $#tag -- @tag[-1] --", join '*',@tag, "\n";
if (@tag[-1] eq 'Total') {
for $i ( 0 .. $#val) {
$_ = $val[$i];
s/([0-9.]+)k/$1*1000/e;
s/([0-9.]+)m/$1*1000*1000/e;
print "$nam/$tag[$i]:$_\n";
}
@tag = @val = ();
}
}
}
Run as: perl reformat.pl < data.file
Or embed in a shell script with the shebang: #!/usr/bin/env perl ...
Btw... if you want to surpress all lines with zeros, change the print to:
$_ and print "$nam/$tag[$i]:$_\n";
Add back in all 'total' lines with:
($_ or $tag[$i] eq 'Total') and print "$nam/$tag[$i]:$_\n";
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 01:01 PM
тАО09-27-2009 01:01 PM
Re: from horizon text format into vertical text format
see attach for the result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2009 01:09 PM
тАО09-27-2009 01:09 PM
Re: from horizon text format into vertical text format
almost time for me to start work. @@~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2009 05:39 AM
тАО09-28-2009 05:39 AM
Re: from horizon text format into vertical text format
I had to abandon you yesterday for family-time. Hein was correct, I failed to see the decimal requirement let alone the last code I posted wasn't quite what we needed.
That said, here's a version that handles integer or decimal values with or without a suffix of "k" or "m". The suffix is evaluated case-insensitively. The output is expressed in integer values, rounded up to the nearest integer. Once again I have used the multiplicative factor of 1024 in lieu of 1000. In all:
# cat ./reformat
#!/usr/bin/perl
use strict;
use warnings;
my ( @first, @second, $slot, $n, $value );
while (<>) {
next if /^===/;
if (m{^\s*\d}) {
@first = split;
next;
}
if (m{^slot}) {
@second = split;
$slot = shift @second;
( $slot = shift @second ) =~ s/://;
}
if ( m{^\s*$} or eof ) {
for ( $n = 0; $n < @first; $n++ ) {
$value = $second[$n];
if ( $value =~ m/k$/i ) {
$value =~ s/((\d+)(\.\d+)?)k/$1*1024/ie;
}
elsif ( $value =~ m/m$/i ) {
$value =~ s/((\d+)(\.\d+)?)m/$1*1024*1024/ie;
}
printf "slot %s/%s:%-8.0f\n", $slot, $first[$n], $value;
}
}
}
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2009 06:25 AM
тАО09-28-2009 06:25 AM
Re: from horizon text format into vertical text format
This is probably lost but just in case a future reader gets this far...
An other way to deal with these suffixes representing multipliers is a table lookup.
This avoids (nested) ifs.
To deal with a missing multiplier append a special characted (or use the newline if there ;-)
Something along the lines of
%mul=qw(x 1 k 1000 m 1000 g 1000000000);
$_ = $text . q(x); # append an 'x' just in case.
m/([0-9.]+)(.)/; # find numbers and multiplier
$value = $1 * $ mul{lc($2)} # and the real value is...
Here is a one-liner if you want to try this
# perl -le %mul=qw(x 1 k 10 m 100 g 1000); while(<>) { chomp; $_.=q(x); m/([0-9.]+)(.)/; print $1*$
mul{$2};}'
fwiw,
Hein.
- « Previous
- Next »