RE: How to parse UNIX commands ...
- From: t.baetzler@xxxxxxxxxx (T Baetzler)
- Date: Fri, 27 Oct 2006 08:44:56 +0200
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
.
- Follow-Ups:
- Re: How to parse UNIX commands ...
- From: kmasaniidc
- Re: How to parse UNIX commands ...
- Prev by Date: Re: How to parse UNIX commands ...
- Next by Date: how to read and process data coming on console
- Previous by thread: Re: How to parse UNIX commands ...
- Next by thread: Re: How to parse UNIX commands ...
- Index(es):
Relevant Pages
|
|