Re: How to parse UNIX commands ...
- From: kmasaniidc@xxxxxxxxxxx
- Date: 27 Oct 2006 00:15:20 -0700
You can as well use perl at command line to evaluate UNIX command
output:
df -k | perl -ane 'print "$F[5]\n" if($F[5])'
T Baetzler wrote:
Hi,
benbart@xxxxxxxxxxxx asked:
How do I parse or evaluate the output of UNIX commands?
For example, in UNIX scripts, I can run filesystem=`df -k |
awk -F"" ' { print
$6 }'` to check for the mount points.
How do I achieve the same in Perl? That is, I tried:
Essentially in the same way - i.e. "my $x = `df -k`".
Maybe I can just simply run system 'df -k', re-direct that
into some output file and then parse it using OPEN-CLOSE
filehandles. Is there any easier way of doing this?
Yes, like this:
open( FH, '-|', 'df -k' ) or die "error: $!";
while( my $line = <FH> ){
# parse df output here
}
close( FH ) or die "error: $!";
I really recommend that you read the sections about open()
in the perlipc manpage. Lots of good stuff there!
HTH,
Thomas
.
- References:
- RE: How to parse UNIX commands ...
- From: T Baetzler
- RE: How to parse UNIX commands ...
- Prev by Date: how to read and process data coming on console
- Next by Date: Re: Sample https:// login script
- Previous by thread: RE: How to parse UNIX commands ...
- Next by thread: how to read and process data coming on console
- Index(es):
Relevant Pages
|