Grep with multiple instances of same pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep with multiple instances of same pattern
# 1  
Old 08-30-2009
Grep with multiple instances of same pattern

Hi,

This is my text file I'm trying to Grep.

Apple Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received End

My Grep command:

grep only--matching 'Location.*Received'
e.

Because the keyword Received appears twice, the Grep command will stop at the last one:
Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received

I want it to stop after the first one:
Location Greenland Rdsds dsds fdfd ddsads http Received


How is that possible?

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep multiple pattern

I have got a text from each line, I need to fetch port only if there is an ip a.text text and port=25 b.ip=(12.32.54.256) and port="52" c.ip=(55.251.253.12) and port=25" d.text text and port="5" e.ip=(45.211.155.15) and port="457" f.ip=(144.158.256.2) and port="588" I know how to... (6 Replies)
Discussion started by: arpagon
6 Replies

2. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

3. Linux

Creating 2 variables from a multiple pattern grep

first time poster here Im pretty new to grep and linux in general and I spent pretty much all day yesterday researching and coming up with a grep command to help with my university project. I am attempting to create a proof of concept bash script to scan the network using ngrep, find appropriate... (7 Replies)
Discussion started by: scottish_jason
7 Replies

4. Shell Programming and Scripting

Grep text between multiple pattern

Hello everybody, I have been looking around but can't figure how to do a grep command, that find the text between multiple patterns, example: (pattern1 OR pattern2) AND (pattern3 OR pattern4) text that I want (pattern5 OR pattern6) AND (pattern7 OR pattern8) So how do I find the "text... (4 Replies)
Discussion started by: Benou
4 Replies

5. Shell Programming and Scripting

Grep multiple instances and send email.

Removed (15 Replies)
Discussion started by: saisneha
15 Replies

6. Programming

Control multiple program instances - open multiple files problem

Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine. So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files. My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Discussion started by: hakermania
3 Replies

7. Shell Programming and Scripting

Grep command with multiple pattern

Hi, I want to search multiple patterns in a variable. DB_ERR=`echo "$DB_TRANS" | grep "SP2-" | grep "ORA-"` echo $DB_ERR But I am not getting anything in DB_ERR. I want to print each line on seperate line. Could you please help me out in this. Thanks in advance. (14 Replies)
Discussion started by: Poonamol
14 Replies

8. Shell Programming and Scripting

How to grep multiple pattern from XML file

Hi Everyone pls if anyone can help me in writing a script or correcting it what I have done. I want to write a script to grep record number for all those record which have abc xyd cat dog in one of the field say VALUE, I have thousand of file in a dir and I want to search every file for... (6 Replies)
Discussion started by: revertback
6 Replies

9. Shell Programming and Scripting

Grep with multiple instances of same pattern

Hi, This is my text file I'm trying to Grep. Apple Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received End My Grep command: grep only--matching 'Location.*Received' Because the keyword Received appears twice, the Grep command will stop at the last... (3 Replies)
Discussion started by: spywarebox
3 Replies

10. Solaris

Multiple pattern on same line using grep

Hi, I would like to search multiple patterns on same line, i.e. all patterns must present on same line. Please suggest. Thanx (2 Replies)
Discussion started by: sanjay1979
2 Replies
Login or Register to Ask a Question
POE::Filter::Stackable(3pm)				User Contributed Perl Documentation			       POE::Filter::Stackable(3pm)

NAME
POE::Filter::Stackable - combine multiple POE::Filter objects SYNOPSIS
#!perl use POE qw( Wheel::FollowTail Filter::Line Filter::Grep Filter::Stackable ); POE::Session->create( inline_states => { _start => sub { my $parse_input_as_lines = POE::Filter::Line->new(); my $select_sudo_log_lines = POE::Filter::Grep->new( Put => sub { 1 }, Get => sub { my $input = shift; return $input =~ /sudo[d+]/i; }, ); my $filter_stack = POE::Filter::Stackable->new( Filters => [ $parse_input_as_lines, # first on get, last on put $select_sudo_log_lines, # first on put, last on get ] ); $_[HEAP]{tailor} = POE::Wheel::FollowTail->new( Filename => "/var/log/system.log", InputEvent => "got_log_line", Filter => $filter_stack, ); }, got_log_line => sub { print "Log: $_[ARG0] "; } } ); POE::Kernel->run(); exit; DESCRIPTION
POE::Filter::Stackable combines multiple filters together in such a way that they appear to be a single filter. All the usual POE::Filter methods work, but data is secretly passed through the stacked filters before it is returned. POE::Wheel objects and stand-alone programs need no modifications to work with a filter stack. In the "SYNOPSIS", POE::Filter::Line and POE::Filter::Grep are combined into one filter that only returns a particular kind of line. This can be more efficient than filtering lines in application space, as fewer events may need to be dispatched and handled. Internally, filters are stored in an array. Data added by get_one_start() will flow through the filter array in increasing index order. Filter #0 will have first crack at it, followed by filter #1 and so. The get_one() call will return an item after it has passed through the last filter. put() passes data through the filters in descending index order. Data will go through the filter with the highest index first, and put() will return the results after data has passed through filter #0. PUBLIC FILTER METHODS
In addition to the usual POE::Filter methods, POE::Filter::Stackable also supports the following. new By default, new() creates an empty filter stack that behaves like POE::Filter::Stream. It may be given optional parameters to initialize the stack with an array of filters. my $sudo_lines = POE::Filter::Stackable->new( Filters => [ POE::Filter::Line->new(), POE::Filter::Grep->new( Put => sub { 1 }, # put all items Get => sub { shift() =~ /sudo[d+]/i }, ), ] ); pop Behaves like Perl's built-in pop() for the filter stack. The highest-indexed filter is removed from the stack and returned. Any data remaining in the filter's input buffer is lost, but an application may always call "get_pending" in POE::Filter on the returned filter. my $last_filter = $stackable->pop(); my $last_buffer = $last_filter->get_pending(); shift Behaves like Perl's built-in shift() for the filter stack. The 0th filter is removed from the stack and returned. Any data remaining in the filter's input buffer is passed to the new head of the stack, or it is lost if the stack becomes empty. An application may also call "get_pending" in POE::Filter on the returned filter to examine the filter's input buffer. my $first_filter = $stackable->shift(); my $first_buffer = $first_filter->get_pending(); push FILTER[, FILTER] push() adds one or more new FILTERs to the end of the stack. The newly pushed FILTERs will process input last, and they will handle output first. # Reverse data read through the stack. # rot13 encode data sent through the stack. $stackable->push( POE::Filter::Map->( Get => sub { return scalar reverse shift() }, Put => sub { local $_ = shift(); tr[a-zA-Z][n-za-mN-ZA-M]; $_ }, ) ); unshift FILTER[, FILTER] unshift() adds one or more new FILTERs to the beginning of the stack. The newly unshifted FILTERs will process input first, and they will handle output last. filters filters() returns a list of the filters inside the Stackable filter, in the stack's native order. Calling "<$filter_stack-"filters()>> in the "SYNOPSIS" would return a list of two filter objects: POE::Filter::Line=ARRAY(0x8b5ee0) POE::Filter::Grep=ARRAY(0x8b5f7c) filter_types filter_types() returns a list of class names for each filter in the stack, in the stack's native order. Calling "<$filter_stack-"filter_types()>> in the "SYNOPSIS" would return a list of two class names: POE::FIlter::Line POE::Filter::Grep It could easily be replaced by: my @filter_types = map { ref } $filter_stack->filters; SEE ALSO
POE::Filter for more information about filters in general. Specific filters, amongst which are: POE::Filter::Block, POE::Filter::Grep, POE::Filter::HTTPD, POE::Filter::Line, POE::Filter::Map, POE::Filter::RecordBlock, POE::Filter::Reference, POE::Filter::Stream BUGS
None currently known. AUTHORS &; COPYRIGHTS The Stackable filter was contributed by Dieter Pearcey. Documentation provided by Rocco Caputo. Please see the POE manpage for more information about authors and contributors. perl v5.14.2 2012-05-15 POE::Filter::Stackable(3pm)