How to parse UNIX commands ...
- From: benbart@xxxxxxxxxxxx
- Date: Fri, 27 Oct 2006 17:30:06 +1300
Hi all,
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:
#!/usr/bin/perl
$x=system 'df -k';
print "============================= \n";
print $x . "\n";
And I am hoping that I can same the results of the df -k output into some kind
of variable that I can then parse and arrange into some format to check for
what logical volumes is mounted into what filesystems etc.
But x gives I believe the result of whether running the system command is
successful or not.
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?
I am not just wanting to do this for the df -k command but also for executing ls
-l | wc -l maybe and some other UNIX commands.
Any advise will be very much appreciated. Thanks ....
.
- Follow-Ups:
- Re: How to parse UNIX commands ...
- From: John W. Krahn
- Re: How to parse UNIX commands ...
- From: Arnaldo Guzman
- Re: How to parse UNIX commands ...
- Prev by Date: Changing colour, font and weight of text in a shell
- Next by Date: Re: How to parse UNIX commands ...
- Previous by thread: Changing colour, font and weight of text in a shell
- Next by thread: Re: How to parse UNIX commands ...
- Index(es):
Relevant Pages
|