Hello all. I am working with the following log file. What I need to do is, for each iteration, grab the date, and for each line with a command of "ns-httpd" grab the PID and Size. Each iteration could have 1-9 instances of "ns-httpd". After I get the information I need, I have to output to a text file in the form of:

Date, PID1, PID1_Size, PID2, PID2_Size,...PID9
12/23, 12222, 300K, 19488, 499K, etc, etc

I don't really even know where to get started, so any suggestions would be greatly appreciated. Part of the logfile i'm working with is as follows:

Thu Dec 19 12:44:34 EST 2002
sleep time=60 seconds
DATE Thu Dec 19 12:44:34 EST 2002
######## Iteration 0 #########

last pid: 18951; load averages: 7.29, 14.09, 16.97 12:44:34
78 processes: 76 sleeping, 1 zombie, 1 on cpu

Memory: 8192M real, 5888M free, 3819M swap in use, 4794M swap free


PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
18916 root 1 41 0 3536K 2832K sleep 0:00 0.32% sshd
18918 root 1 41 0 3536K 2832K sleep 0:00 0.32% sshd
18919 root 1 48 0 3536K 2832K sleep 0:00 0.32% sshd
18917 root 1 48 0 3536K 2832K sleep 0:00 0.31% sshd
18647 root 149 58 0 470M 214M sleep 5:27 0.24% ns-httpd
17932 root 139 58 0 469M 211M sleep 5:19 0.23% ns-httpd
18626 root 140 58 0 468M 203M sleep 3:29 0.22% ns-httpd
18668 root 159 58 0 469M 199M sleep 2:59 0.20% ns-httpd
18605 root 165 58 0 469M 205M sleep 3:49 0.19% ns-httpd
18710 root 145 58 0 468M 197M sleep 3:04 0.18% ns-httpd
18689 root 131 58 0 468M 199M sleep 3:10 0.17% ns-httpd
18947 root 1 0 0 1792K 1200K cpu/4 0:00 0.13% top
18731 root 144 58 0 468M 199M sleep 3:08 0.13% ns-httpd
744 root 1 58 0 2632K 1376K sleep 0:04 0.02% sshd
18940 root 1 18 0 1840K 1376K sleep 0:00 0.01% processmonitor.
DATE Thu Dec 19 12:44:34 EST 2002
######## Iteration 1 #########

last pid: 18951; load averages: 7.29, 14.09, 16.97 12:44:34
78 processes: 76 sleeping, 1 zombie, 1 on cpu

Memory: 8192M real, 5888M free, 3819M swap in use, 4794M swap free


PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
18916 root 1 41 0 3536K 2832K sleep 0:00 0.32% sshd
18918 root 1 41 0 3536K 2832K sleep 0:00 0.32% sshd
18919 root 1 48 0 3536K 2832K sleep 0:00 0.32% sshd
18917 root 1 48 0 3536K 2832K sleep 0:00 0.31% sshd
18647 root 149 58 0 470M 214M sleep 5:27 0.24% ns-httpd
17932 root 139 58 0 469M 211M sleep 5:19 0.23% ns-httpd
18626 root 140 58 0 468M 203M sleep 3:29 0.22% ns-httpd
18668 root 159 58 0 469M 199M sleep 2:59 0.20% ns-httpd
18605 root 165 58 0 469M 205M sleep 3:49 0.19% ns-httpd
18710 root 145 58 0 468M 197M sleep 3:04 0.18% ns-httpd
18689 root 131 58 0 468M 199M sleep 3:10 0.17% sshd
18947 root 1 0 0 1792K 1200K cpu/4 0:00 0.13% top
18731 root 144 58 0 468M 199M sleep 3:08 0.13% ns-httpd
744 root 1 58 0 2632K 1376K sleep 0:04 0.02% sshd
18940 root 1 18 0 1840K 1376K sleep 0:00 0.01% processmonitor.

In reply to Extracting a whole line from text file when a keyword is found by maddox3131

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.