Visit Our UNIX and Linux User Community


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

Previous Thread | Next Thread
Test Your Knowledge in Computers #511
Difficulty: Medium
Many programming languages do not allow you to begin a variable name with a number as it would make it more difficult for a compiler or interpreter to parse a program's source code.
True or False?

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
Received(3pm)						User Contributed Perl Documentation					     Received(3pm)

NAME
Mail::Field::Received -- mostly RFC822-compliant parser of Received headers SYNOPSIS
use Mail::Field; my $received = Mail::Field->new('Received', $header); my $results = $received->parse_tree(); my $parsed_ok = $received->parsed_ok(); my $diagnostics = $received->diagnostics(); DESCRIPTION
Don't use this class directly! Instead ask Mail::Field for new instances based on the field name! Mail::Field::Received provides subroutines for parsing Received headers from e-mails. It mostly complies with RFC822, but deviates to accommodate a number of broken MTAs which are in common use. It also attempts to extract useful information which MTAs often embed within the "(comments)". It is a subclass derived from the Mail::Field and Mail::Field::Generic classes. ROUTINES
o debug Returns current debugging level obtained via the "diagnostics" method. If a parameter is given, the debugging level is changed. The default level is 3. o diagnose $received->diagnose("foo", " "); Appends stuff to the parser's diagnostics buffer. o diagnostics my $diagnostics = $received->diagnostics(); Returns the contents of the parser's diagnostics buffer. o parse The actual parser. Returns the object (Mail::Field barfs otherwise). o parsed_ok if ($received->parsed_ok()) { ... } Returns true if the parse succeed, or if it failed, but was permitted to fail for some reason, such as encountering evidence of a known broken (non-RFC822-compliant) format mid-parse. o parse_tree my $parse_tree = $received->parse_tree(); Returns the actual parse tree, which is where you get all the useful information. It is returned as a hashref whose keys are strings like `from', `by', `with', `id', `via' etc., corresponding to the components of Received headers as defined by RFC822: received = "Received" ":" ; one per relay ["from" domain] ; sending host ["by" domain] ; receiving host ["via" atom] ; physical path *("with" atom) ; link/mail protocol ["id" msg-id] ; receiver msg id ["for" addr-spec] ; initial form ";" date-time ; time received The corresponding values are more hashrefs which are mini-parse-trees for these individual components. A typical parse tree looks something like: { 'by' => { 'domain' => 'host5.hostingcheck.com', 'whole' => 'by host5.hostingcheck.com', 'comments' => [ '(8.9.3/8.9.3)' ], }, 'date_time' => { 'year' => 2000, 'week_day' => 'Tue', 'minute' => 57, 'day_of_year' => '1 Feb', 'month_day' => ' 1', 'zone' => '-0500', 'second' => 18, 'hms' => '21:57:18', 'date_time' => 'Tue, 1 Feb 2000 21:57:18 -0500', 'hour' => 21, 'month' => 'Feb', 'rest' => '2000 21:57:18 -0500', 'whole' => 'Tue, 1 Feb 2000 21:57:18 -0500' }, 'with' => { 'with' => 'ESMTP', 'whole' => 'with ESMTP' }, 'from' => { 'domain' => 'mediacons.tecc.co.uk', 'HELO' => 'tr909.mediaconsult.com', 'from' => 'tr909.mediaconsult.com', 'address' => '193.128.6.132', 'comments' => [ '(mediacons.tecc.co.uk [193.128.6.132])', ], 'whole' => 'from tr909.mediaconsult.com (mediacons.tecc.co.uk [193.128.6.132]) ' }, 'id' => { 'id' => 'VAA24164', 'whole' => 'id VAA24164' }, 'comments' => [ '(mediacons.tecc.co.uk [193.128.6.132])', '(8.9.3/8.9.3)' ], 'for' => { 'for' => '<adam@spiers.net>', 'whole' => 'for <adam@spiers.net>' }, 'whole' => 'from tr909.mediaconsult.com (mediacons.tecc.co.uk [193.128.6.132]) by host5.hostingcheck.com (8.9.3/8.9.3) with ESMTP id VAA24164 for <adam@spiers.net>; Tue, 1 Feb 2000 21:57:18 -0500' } BUGS
Doesn't use Parse::RecDescent, which it maybe should. Doesn't offer a `strict RFC822' parsing mode. To implement that would be a royal pain in the arse, unless we move to Parse::RecDescent. SEE ALSO
Mail::Field, Mail::Header AUTHOR
Adam Spiers <adam@spiers.net> LICENSE
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2011-02-05 Received(3pm)

Featured Tech Videos