#!/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
In reply to Re: Parsing output from a command
by Limbic~Region
in thread Parsing output from a command
by ronix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |