Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file. And then copy 200 lines above ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    13

    Script to identify the line number containing a particular "string"

    Hi,

    I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file.

    And then copy 200 lines above that line number to a new file.

    Can someone provide pointers on how to write this script or what command to be used ?

    Any help would be highly appreciated.


    Thanks in advnace,

  2. #2
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    Code:
    #!/usr/bin/perl
    use warnings;
    use strict;
    
    open LOG, "<logfile.log";
    while(<LOG>)
    {  
      if ( $_ =~ m/LOOKING FOR/ )
      {
         print "yeyFOUND!";
      }
    }
    close LOG;
    use perl for this
    That is a little sample you'll just have to add the Copy part =)
    New Users, please read this..
    Google first, then ask..

  3. #3
    Just Joined!
    Join Date
    Jan 2007
    Posts
    15
    Look into wc -l, awk and cut.

    xwulfgar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...