Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

How do i split the output of ps -aef

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


Description:

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!
  • 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (9)
    As of 2015-07-04 08:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (58 votes), past polls