Sponsored Content
Top Forums Shell Programming and Scripting Perl to Search through next lines Post 302367938 by bataf on Tuesday 3rd of November 2009 08:50:30 PM
Old 11-03-2009
Perl to Search through next lines

I have log file that I need to extract time difference occurance when two events happend, between first occurance of TV and when W_NO happend. also read the value=, below example...I can only read the next line but not able to seach all the next lines untill i see W_NO..

Thanks for your help.
Bataf


11/03/2009 07:28:27 TV
11/03/2009 07:28:35 TV
11/03/2009 07:28:37
11/03/2009 07:38:30
11/03/2009 07:39:00 W_NO value="A00005FF.rf"
11/03/2009 07:40:40 TV
11/03/2009 07:40:40
11/03/2009 07:40:42
11/03/2009 07:40:44 W_NO value="A00008FF.rf"
11/03/2009 07:42:57
11/03/2009 07:45:08
11/03/2009 07:45:08 W_NO value="A0058FF.rf"
11/03/2009 07:45:10
11/03/2009 07:45:12
11/03/2009 07:51:47 TV
11/03/2009 07:53:37
11/03/2009 07:53:38
11/03/2009 07:53:38 W_NO value="A070058FF.rf"
11/03/2009 07:55:49
11/03/2009 07:55:49
11/03/2009 07:57:59 W_NO value="A00008FF.rf"
11/03/2009 07:57:59
11/03/2009 08:00:10 TV
11/03/2009 08:00:10 W_NO value="A077758FF.rf"
11/03/2009 08:02:20

Code:
 
while( $line = <FILE>){
 chomp ($line);
  my ($fdate,undef)= split(" ",$line);
 #print "$fdate $cdate\n";
 if ($fdate =~ /$curr_date/  && $line =~ m/TV)  {
  $tv++;
  #$nextline = <FILE>;
  my $next =<FILE>;
  
  if ($next =~ m/W_NO/){
   print "$next\n";
   $line = $next
   
   }
  }

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

2. Shell Programming and Scripting

combine two perl lines into a single perl command

Hi Everyone, i have a string 00:44:40 so: $tmp=~ s/://gi; $tmp=~s/({2})({2})({2})/$1*3600+$2*60+$3/e; the output is 2680. Any way to combine this two lines into a single line? Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

3. Shell Programming and Scripting

Search in a set of lines using perl

Hi Experts, i am beginner in perl and need your help to find a solution.. I have a block of multiple lines like below say module 1 to module 100 ***** MAKING > module1 ************** kvmfkvmmfdv svksmnvlksmfvks dcsdvcs sddvcsv ssvsdvdf error: abcdefghi wrw wvsv dsvds sdvsd error:... (5 Replies)
Discussion started by: ganga.dharan
5 Replies

4. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

5. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

6. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

7. Shell Programming and Scripting

Search and swap multiple lines in file using Perl

Hi all, I have a vcd file with a bunch of lines containing an array, like this $var wire 1 b a $end $var wire 1 c a $end $var wire 1 d a $end $var wire 1 e a $end $var wire 1 f b $end $var wire 1 g b $end $var wire 1 h b $end $var wire 1 i b $end I want it like this: $var wire 1 e a... (12 Replies)
Discussion started by: veerabahu
12 Replies

8. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

9. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

10. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies
EXIGREP(8)						      System Manager's Manual							EXIGREP(8)

NAME
EXIGREP - Search Exim's main log SYNOPSIS
exigrep [-l] pattern [log file] ... DESCRIPTION
The exigrep utility is a Perl script that searches one or more main log files for entries that match a given pattern. When it finds a match, it extracts all the log entries for the relevant message, not just those that match the pattern. Thus, exigrep can extract complete log entries for a given message, or all mail for a given user, or for a given host, for example. The -l flag means 'literal', that is, treat all characters in the pattern as standing for themselves. Otherwise the pattern must be a Perl regular expression. The pattern match is case-insensitive. If no file names are given on the command line, the standard input is read. If the location of a zcat command is known from the definition of ZCAT_COMMAND in Local/Makefile, exigrep automatically passes any file whose name ends in COMPRESS_SUFFIX through zcat as it searches it. BUGS
This manual page needs a major re-work. If somebody knows better groff than us and has more experience in writing manual pages, any patches would be greatly appreciated. SEE ALSO
exim(8), perlre(1), /usr/share/doc/exim4-base/ AUTHOR
This manual page was stitched together from spec.txt by Andreas Metzler <ametzler at downhill.at.eu.org>, for the Debian GNU/Linux system (but may be used by others). March 26, 2003 EXIGREP(8)
All times are GMT -4. The time now is 09:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy