I just wrote something with awk which fetches my unix ps -ef output where I eliminate the awk and /bin/ksh part of the script that is fetching my ps -ef output:
jones 11111 33334 09:37:46 awk jones 11113 44454 09:37:46 grep jones 11123 33334 09:37:46 /bin/ksh jones 11118 22234 06:18:58 -ksh
to this
jones 11135 44322 09:39:38 grep jones 11118 22234 06:18:58 -ksh
Here is how I did it with Unix:
ps -ef | grep Jones | awk '$8 !~ /awk/ && $8 !~ /\/bin\/ksh/ \ {print $1" "$2" "$3" "$5" "$8}'
Now my attempt to do it with perl shows this in my output file:
jones 11111 55555 0 09:42:09 pts/1 0:00 /usr/local/bin/perl ps1 jones 22222 66666 0 09:42:09 pts/1 0:00 grep jones jones 33333 77777 0 09:42:09 pts/1 0:00 sh -c ps -ef | grep jones +> out r jones 44444 88888 0 06:18:58 pts/1 0:01 -ksh
I want this output (the same as I got in my unix script):
jones 22222 66666 0 09:42:09 pts/1 0:00 grep jones jones 44444 88888 0 06:18:58 pts/1 0:01 -ksh
Here is my attempt at it in Perl. Please advise how I can improve this so it works???
#!/usr/local/bin/perl system("ps -ef | grep Jones > outr"); $outr = 'outr'; open(OF, "$outr") || die "Can not open $outr: $!\n"; @data=(<OF>); close(OF); open(OF,">$outr") || die "File not opening $outr: $!\n"; foreach $_ (@data) { next if ($_ !~ m/\/usr/local/bin/perl ps1$/) && ($_ !~ /sh \-c ps \-ef + \| grep jones \> out) ; print OF $_; } close(OF);

In reply to Trying to grab process output. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.