All,
I need to get certain elements of the output of
`pkginfo -l` on a Solaris system.
Using Korn Shell, is there any syntax similar to the following
Perl snippet:
open( PKGINFO, "/bin/pkginfo -l |" ); # creates a filehandle
while( chop( $line = <PKGINFO> ) ) {
if ( index( $line, " PKGINST: " ) == 0 ) {
$pkg = substr( $line, 13 );
} elsif( index( $line, " CATEGORY: " ) == 0 ) {
$cat = substr( $line, 13 );
} elsif( index( $line, " VERSION: " ) == 0 ) {
$ver = substr( $line, 13 );
printf( "%-13s %-22s %s\n", $pkg, $cat, $ver );
}
}
For whatever reason, I need to use shell instead of Perl, and
converting sequences like the above have proven difficult at
best.
I have considered redirecting stdout to a file, then using
sed or awk to get the bits of info I need, but that seems
shabby. Am I missing something?
TIA for any insight