How to parse UNIX commands ...



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 ....



.



Relevant Pages

  • Re: add all lines of a textfile
    ... Tassos wrote: ... > Is there a way using unix commands, to parse a textfile with numbers and ...
    (comp.unix.shell)
  • Re: add all lines of a textfile
    ... > Is there a way using unix commands, to parse a textfile with numbers and ... > produce an output which is equal to the sum of all of them? ...
    (comp.unix.shell)
  • Re: How to parse UNIX commands ...
    ... How do I parse or evaluate the output of UNIX commands? ... How do I achieve the same in Perl? ... I am not just wanting to do this for the df -k command but also for executing ls ...
    (perl.beginners)
  • add all lines of a textfile
    ... Is there a way using unix commands, to parse a textfile with numbers and produce an output ... which is equal to the sum of all of them? ...
    (comp.unix.shell)
  • unix commands project?
    ... I could have sworn that there was a project at one point to replace ... the "basic" Unix commands with perl ... scripts. ...
    (comp.lang.perl.misc)