Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

How do i split the output of ps -aef

by Anthanos (Initiate)
on Jan 25, 2001 at 03:23 UTC ( #54152=categorized question: print w/replies, xml ) Need Help??
Contributed by Anthanos on Jan 25, 2001 at 03:23 UTC
Q&A  > regular expressions


I want to process individual lines from theoutput of ps -aef but the spacing is weird. Is there a way to split it into columns? The spacing seems to be dynamic based on the lengths of the column contents. Thanks!

Answer: How do i split the output of ps -aef
contributed by AltBlue

maybe you'd like to take a look to Proc::ProcessTable.

Note from sintadil: Proc::ProcessTable is platform-dependent and -- at least on the systems with which I'm familiar -- it depends on the existence of a procfs. procfs is strongly deprecated in some Unix versions and doesn't even exist by default in some.

Answer: How do i split the output of ps -aef
contributed by arturo

I take it you mean the output of that command produces fields separated by a variable amount of whitespace. The solution is to split on one-or-more whitespace characters, just do @bits = split /\s+/, $string;

Please (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2018-06-23 07:05 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.