Sponsored Content
Top Forums Shell Programming and Scripting if match found go to a particular line in perl Post 302180394 by user_prady on Monday 31st of March 2008 03:38:57 AM
Old 03-31-2008
Quote:
Originally Posted by KevinADC
You could do something like this:

Code:
use strict;
use warnings;
my $flag = 0;
my $last_line;
while(<DATA>){
   if(/^\*Main Start/){
      $flag = 1;
   }
   elsif($flag && /^\*Main End/) {
         $numbers = (split(',',$last_line))[0];
         $last_line = '';
         $flag = 0; 
         print $numbers,"\n";
   }
   else {
      $last_line = $_;
      next;
   }
}	
__DATA__
*Init End
*Main Start
*Comment Reset Timers
000000,0000,0,0,0,0,0,1,0
000000,0000,0,0,0,0,1,1,0 
*Comment Control Frame at 1.04596 ms
000000,0400,0,0,0,0,1,0,1
2418A4,0000,0,1,3,0,0,0,0 
049C00,0000,0,0,2,0,0,0,0
*Comment Control Frame at 1.04673 ms
*Comment Control Frame at
000002,0000,0,0,0,0,1,0,1
241002,0000,0,1,3,0,0,0,0
000100,0000,0,0,2,0,0,0,0
*Comment Control Frame at
000004,0000,0,0,0,0,1,0,1
241002,0000,0,1,3,0,0,0,0
000000,0000,0,0,2,0,0,0,0
*Comment Frame 13 at ** us,,,,,,,,
000005,7E3D,0,0,0,0,1,0,1
*Main End,,,,,,,,

Yes Kevin . I am pretty close to my goal but one thing that I want the number (ie, 000005) when *Main Start pattern found .

Regards,
user_prady
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Match a line with multiple search patterns

Hi I'm not very good with the serach patterns and I'd need a sample how to find a line that has multiple patterns. Say I want to find a line that has "abd", "123" and "QWERTY" and there can be any characters or numbers between the serach patterns, I have a file that has thousands of lines and... (10 Replies)
Discussion started by: Juha
10 Replies

2. Shell Programming and Scripting

help with script to send email and if subject line match is found

Help with script that will check log, then find a match is found, add that as the subject line. 1. The script will always run as a deamon.. and scan the event.log file 2. when a new 101 line is added to the event.log file, have the script check position 5,6 and 7 which is the job name, which... (2 Replies)
Discussion started by: axdelg
2 Replies

3. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

4. UNIX for Dummies Questions & Answers

Display n lines after match found and other line

I have a file like this DoctorName Address1 Address2 DOB InsuredName Address1 Address2 DOB PatientName Address1 Address2 DOB ClaimNo1 DoctorName Address1 Address2 DOB InsuredName (2 Replies)
Discussion started by: nsuresh316
2 Replies

5. Shell Programming and Scripting

Displaying text till pattern match found in a line

Hi All, From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able to print text before the pattern. it display texts which is found after pattern. awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//' input... (4 Replies)
Discussion started by: Optimus81
4 Replies

6. Shell Programming and Scripting

How to print the entire line if the mentioned match is found?

Hello Everyone, I have a file with 5 fields in each line just like mentioned below. Also the 4th field is time elapsed(hh:mm:ss) since the process is running xyz abc status 23:00:00 idle abc def status 24:00:00 idle def gji status 27:00:02 idle fgh gty status 00:00:00 idle Here I... (8 Replies)
Discussion started by: rahul2662
8 Replies

7. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

8. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

9. Shell Programming and Scripting

Add comment on last line if found match

Hi All, totally new on it , normally use it for just 1 line. i'm looking for help. i'm have 2 file. file 1 : -------------------------------------------------- c12 c1 c3 -------------------------------------------------- file 2: other content ... (10 Replies)
Discussion started by: kttan
10 Replies

10. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies
XML::LibXML::NodeList(3)				User Contributed Perl Documentation				  XML::LibXML::NodeList(3)

NAME
XML::LibXML::NodeList - a list of XML document nodes DESCRIPTION
An XML::LibXML::NodeList object contains an ordered list of nodes, as detailed by the W3C DOM documentation of Node Lists. SYNOPSIS
my $results = $dom->findnodes('//somepath'); foreach my $context ($results->get_nodelist) { my $newresults = $context->findnodes('./other/element'); ... } API
new(@nodes) You will almost never have to create a new NodeList object, as it is all done for you by XPath. get_nodelist() Returns a list of nodes, the contents of the node list, as a perl list. string_value() Returns the string-value of the first node in the list. See the XPath specification for what "string-value" means. to_literal() Returns the concatenation of all the string-values of all the nodes in the list. get_node($pos) Returns the node at $pos. The node position in XPath is based at 1, not 0. size() Returns the number of nodes in the NodeList. pop() Equivalent to perl's pop function. push(@nodes) Equivalent to perl's push function. append($nodelist) Given a nodelist, appends the list of nodes in $nodelist to the end of the current list. shift() Equivalent to perl's shift function. unshift(@nodes) Equivalent to perl's unshift function. prepend($nodelist) Given a nodelist, prepends the list of nodes in $nodelist to the front of the current list. map($coderef) Equivalent to perl's map function. grep($coderef) Equivalent to perl's grep function. sort($coderef) Equivalent to perl's sort function. Caveat: Perl's magic $a and $b variables are not available in $coderef. Instead the two terms are passed to the coderef as arguments. reverse() Equivalent to perl's reverse function. foreach($coderef) Inspired by perl's foreach loop. Executes the coderef on each item in the list. Similar to "map", but instead of returning the list of values returned by $coderef, returns the original NodeList. reduce($coderef, $init) Equivalent to List::Util's reduce function. $init is optional and provides an initial value for the reduction. Caveat: Perl's magic $a and $b variables are not available in $coderef. Instead the two terms are passed to the coderef as arguments. perl v5.16.2 2012-10-22 XML::LibXML::NodeList(3)
All times are GMT -4. The time now is 11:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy