- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: perl script reformat
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
Forums
Discussions
Discussions
Discussions
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
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
04-01-2010 06:31 AM
04-01-2010 06:31 AM
DISKPART>
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 G Data File NTFS Partition 1000 GB Healthy
Volume 1 H Quorum NTFS Partition 1020 MB Healthy
Volume 2 Partition 2000 GB Healthy
Volume 3 C NTFS Partition 137 GB Healthy System
DISKPART>
## end of input file
using perl,
if "Size" column equals to 2000GB, then output
"select volume 2"
"assign letter=G"
if "size" column equals to 1000GB, then output
"select volume 0"
"assign letter=H"
if "size" column equals to 1020MB, then output
"select volume 1"
"assign letter=Q"
Typically, when running the sciprt, should be able to read from input file,
reformat, then output like following; the input file content will dynamicly changes
select volume 2
assign letter=G
select volume 0
assign letter=H
select volume 1
assign letter=G
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2010 07:02 AM
04-01-2010 07:02 AM
Re: perl script reformat
You could do something like this:
# cat ./reformat
#!/usr/bin/perl
use strict;
use warnings;
my ( $size, $units );;
while (<>) {
next if $. < 3; #...skip two header lines...
( $size, $units ) = m{\s(\d+)\s+(.B)\s};
if ( $size == 2000 and $units eq 'GB' ) {
print "select volume 2\nassign letter=G\n"
}
elsif ( $size == 1000 and $units eq 'GB' ) {
print "select volume 0\nassign letter=H\n"
}
elsif ( $size == 1020 and $units eq 'MB' ) {
print "select volume 1\nassign letter=Q\n"
}
}
1;
...run as :
# ./reformat file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2010 07:19 AM
04-01-2010 07:19 AM
Re: perl script reformat
in the output "select volume 2", string "2" will refer to original input file field 2.
for 2000GB volume, it will dedicate map to G
for 1000GB volume, it will dedicate map to H
for 1020MB volume, it will dedicate map to Q
but input file, the first and the second field will change dynamically.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2010 07:51 AM
04-01-2010 07:51 AM
Solution> in the output "select volume 2", string "2" will refer to original input file field 2.
You didn't make that very clear, originally. Good specifications make for good code.
Here's the revised version which tolerates fuzzier input. Note that a valid line begins with "Volume" and can be found to contain whitespace delimited "size" and "units" fields.
# cat ./reformat
#!/usr/bin/perl
use strict;
use warnings;
while (<>) {
my ( $volno, $size, $units ) = m{^Volume\s(\d+)\s+.+?(\d+)\s*(.B)\s};
next unless defined $size;
if ( $size == 2000 && $units eq 'GB' ) {
print "select volume $volno\nassign letter=G\n"
}
elsif ( $size == 1000 && $units eq 'GB' ) {
print "select volume $volno\nassign letter=H\n"
}
elsif ( $size == 1020 && $units eq 'MB' ) {
print "select volume $volno\nassign letter=Q\n"
}
}
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2010 07:58 AM
04-01-2010 07:58 AM
Re: perl script reformat
Volume ### Ltr Label Fs Type Size Status Info
my %size = (
kb => 1024,
mb => 1024 * 1024,
gb => 1024 * 1024 * 1024,
);
while (<>) {
my ($vol, $xxx, $ltr, $lbl, $fs, $type, $size, $status, $info) = unpack "A11 A3 A11 A5 A10 A7 A9 A*", $_;
$size =~ s/^\s*(\d+)\s*([kKmMgG][bB])/$1*$size{lc$2}/e;
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2010 09:47 AM
04-01-2010 09:47 AM
Re: perl script reformat
After some modify, it matches my requirement.