in reply to Parsing output from a command
#!/usr/bin/perl use strict; use warnings; open(my $cfg, '-|', 'lscfg -vl hdisk*') or die "Unable to open pipe to + lscfg: $!"; { local $/ = "\nhdisk"; while (<$fh>) { chomp; $_ = $/ . $_ if $. != 1; my ($disk) = $_ =~ /^(hdisk\w+)/; my ($serial) = $_ =~ /Serial Number\.+(\w+)/; if ($disk && $serial) { print "$disk\t$serial\n"; } else { # enhance parser to handle follow situation die $_; } } }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing output from a command
by BrowserUk (Patriarch) on Mar 24, 2009 at 16:24 UTC | |
by Limbic~Region (Chancellor) on Mar 24, 2009 at 17:40 UTC | |
by BrowserUk (Patriarch) on Mar 24, 2009 at 18:33 UTC | |
by Limbic~Region (Chancellor) on Mar 24, 2009 at 19:06 UTC |