11299 pts/4 00:00:00 su 11303 pts/4 00:00:00 bash 11403 tty2 00:00:00 bsc_static 11406 tty2 00:00:00 rtpTrau_static 11408 tty2 00:11:30 hullBts_static 11418 pts/4 00:00:00 tail 12157 pts/5 00:00:00 su
the above lines are part of a file. the first 4 digits (or more) in each line make up the PID number(in this case there are 5 digits)...eg. 11403 the last column of each line has the file name. eg. su i need to find out PID number for the file name "hullBts_static"(in the above case it is 11408.......please mind that "hullBts_static" will not always be in the same line as shown... as the file entries change each time i run it).... then i need to generate a file name using the above found PID. this file name is of the form "frag_ PID.log"... in other words , the new filename will consist the matched PID. this file name will now have to be piped into a shell script file. my code looks like this....is it correct??
#!usr/bin/perl while(<>) { if(/^([\d]+)*(hullBts_static)/) { my $var1= "frag_$1.log"; } print STDOUT $var1; }

In reply to Parsing 'ps' output by vineet2004

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.