Loading ...
Sorry, an error occurred while loading the content.
 

SED and AWK

Expand Messages
  • Peter Pan
    Hopefully someone can help. I have multiple log files that are being created during my build. At the end of each build, I copy the log file to 1 master log
    Message 1 of 5 , Feb 9, 2006
      Hopefully someone can help.

      I have multiple log files that are being created during my build. At
      the end of each build, I copy the log file to 1 master log file. I
      need a way using sed or awk where I can scan the master files for
      "Error: building module..." If this pattern is hit I need to copy
      that line and up 25 lines into a new file error.log.

      Any suggestions???

      Thanks
    • merlyn@stonehenge.com
      ... Peter I have multiple log files that are being created during my build. At Peter the end of each build, I copy the log file to 1 master log file. I
      Message 2 of 5 , Feb 9, 2006
        >>>>> "Peter" == Peter Pan <usl911@...> writes:

        Peter> I have multiple log files that are being created during my build. At
        Peter> the end of each build, I copy the log file to 1 master log file. I
        Peter> need a way using sed or awk where I can scan the master files for
        Peter> "Error: building module..." If this pattern is hit I need to copy
        Peter> that line and up 25 lines into a new file error.log.

        Peter> Any suggestions???

        Yes, don't use sed or awk. Use Perl.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • Peter Pan
        OK. How would I do this in perl. I guess I could write a script to call my perl script that runs this command ... build. At ... file. I ... files for ... to
        Message 3 of 5 , Feb 9, 2006
          OK. How would I do this in perl. I guess I could write a script to
          call my perl script that runs this command

          --- In perl-beginner@yahoogroups.com, merlyn@... wrote:
          >
          > >>>>> "Peter" == Peter Pan <usl911@...> writes:
          >
          > Peter> I have multiple log files that are being created during my
          build. At
          > Peter> the end of each build, I copy the log file to 1 master log
          file. I
          > Peter> need a way using sed or awk where I can scan the master
          files for
          > Peter> "Error: building module..." If this pattern is hit I need
          to copy
          > Peter> that line and up 25 lines into a new file error.log.
          >
          > Peter> Any suggestions???
          >
          > Yes, don't use sed or awk. Use Perl.
          >
          > --
          > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
          777 0095
          > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
          > See PerlTraining.Stonehenge.com for onsite and open-enrollment
          Perl training!
          >
        • merlyn@stonehenge.com
          ... Peter OK. How would I do this in perl. I guess I could write a script to Peter call my perl script that runs this command You would do it by learning
          Message 4 of 5 , Feb 10, 2006
            >>>>> "Peter" == Peter Pan <usl911@...> writes:

            Peter> OK. How would I do this in perl. I guess I could write a script to
            Peter> call my perl script that runs this command

            You would do it by learning some Perl, then perhaps when you get stuck, asking
            a *Perl* question here. There are plenty of resources for that... see
            http://learn.perl.org for the canonical list.

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
            See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
          • Damien Carbery
            ... The algorithm I would use would be: - Open log file. - Read lines. - If line contains Error: building module then read more lines until you ve read 25
            Message 5 of 5 , Feb 10, 2006
              --- In perl-beginner@yahoogroups.com, "Peter Pan" <usl911@...> wrote:
              >
              > OK. How would I do this in perl. I guess I could write a script to
              > call my perl script that runs this command
              >

              The algorithm I would use would be:
              - Open log file.
              - Read lines.
              - If line contains 'Error: building module' then read more lines until
              you've read 25 lines or until you reach the end of file.

              #!/usr/bin/perl -w

              use strict;

              my $log;
              # Log file is first argument on command line.
              $log = $ARGV[0] if ( @ARGV );

              if ( defined $log )
              {
              if ( open( FH, "$log" ) )
              {
              while ( my $line = <FH> )
              {
              if ( $line =~ /Error: building module/ )
              {
              print $line;
              # $. is the current line number.
              my $current_line = $.;
              while ( ( $line = <FH> ) && ( $. < $current_line + 25 ) )
              {
              print $line;
              }
              }
              }
              close( FH );
              }
              }

              > --- In perl-beginner@yahoogroups.com, merlyn@ wrote:
              > >
              > > >>>>> "Peter" == Peter Pan <usl911@> writes:
              > >
              > > Peter> I have multiple log files that are being created during my
              > build. At
              > > Peter> the end of each build, I copy the log file to 1 master log
              > file. I
              > > Peter> need a way using sed or awk where I can scan the master
              > files for
              > > Peter> "Error: building module..." If this pattern is hit I need
              > to copy
              > > Peter> that line and up 25 lines into a new file error.log.
              > >
              > > Peter> Any suggestions???
              > >
              > > Yes, don't use sed or awk. Use Perl.
              > >
              > > --
              > > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
              > 777 0095
              > > <merlyn@> <URL:http://www.stonehenge.com/merlyn/>
              > > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
              > > See PerlTraining.Stonehenge.com for onsite and open-enrollment
              > Perl training!
              > >
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.