You can edit the file in place using this:
syslog before the following command: Oct 7 08:30:01 deneb sendmail[13183]: [ID 801593 mail.info] g97CU1r13 +183: from= cmjohnso, size=252, class=0, nrcpts=1, msgid=<200210071230.g97CU1r1318 +3@deneb.us lec.net>, relay=cmjohnso@localhost Oct 7 08:30:01 deneb sendmail[13185]: [ID 801593 mail.info] g97CU1r13 +183: to=cm johnso, ctladdr=cmjohnso (10052/1), delay=00:00:00, xdelay=00:00:00, m +ailer=loca l, pri=120252, relay=local, dsn=2.0.0, stat=Sent % perl -i -p del.pl /var/log/syslog syslog after the above command: cmjohnso@deneb$ cat syslog Oct Oct
Here is a code example for del.pl:
#!/usr/bin/perl -w use strict; my @line = split(" ",$_); print "$line[0]\n"; $_ = '';
Remember, when you are in the del.pl program you are only working on one line at a time, the 'perl -i -p <progrname> <file>' line reads each line of the file, in this case /var/log/syslog and applies the code in the program to each line, printing whatever you print in the code as well as the final content of $_. That is why I set $_ to '', so it did not print back to my file. It would have been just as east to set $_ to what I wanted to be printed to the file and not done the print myself.

You could write a program somewhat similar to this that evaluated each line and if it needs to be deleted from the file just set $_ to '' otherwise leave $_ alone and it will go back to your final file as it was when it entered the loop.

Here is the text from the "Perl Black Book" by Coriolis:

"Perl lets you make changes to files in-place--that is, make changes to the file directly, without having to explicitly read it in and write it out. To edit files in-place, you use the -i switch with Perl; this switch specifies that files processed with the <> construct to be edited in-place. ....... Note also the -p switch; this switch makes Perl use a while (<>) and print loop around your script to print the changed text back to the file."


In reply to Re: cleaning up logs by gnu@perl
in thread cleaning up logs by ddrumguy

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.