LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 09-02-2010, 12:31 AM   #1
saheervc
LQ Newbie
 
Registered: Mar 2009
Posts: 3
Blog Entries: 1

Rep: Reputation: 0
multiple pattern search in a single file line by line


Hi Guys, Im a new to Linux.
Can some one help me to sort out the following problem.

I have a very long output file ( some 104735 lines ) generated by a program. I have to check this output file for errors. The file looks like the following .

...............................................................
I=1
...
...
NO CONVERGENCE
....

..
I=2
...
..
CONVERGENCE REACHED
...
...
..
I=3
...
..
NO CONVERGENCE
...
..
MAXIMUM NUMBER OF ITERATIONS REACHED
...
..
etc upto I=48

..................................................................
It is very difficult to go through each line for errors.

I would like to write a script file that prints only errors under iteration number in the following way.
.........................................................
I=1
NO CONVERGENCE
I=3
NO CONVERGENCE
MAXIMUM NUMBER OF ITERATIONS REACHED
...

.........................................................

Im using Mandriva 2010
Thanks in Advance.
 
Old 09-02-2010, 12:44 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Code:
awk '/^I=/{i=$0}/^NO CONVERGENCE|MAX.*ITERATIONS.*REACHED/{print i,$0}' file
 
1 members found this post helpful.
Old 09-02-2010, 12:45 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Hi, welcome to LQ!

Given the data above something like
Code:
egrep "^I=|NO CONVERGENCE|MAXIMUM NUMBER OF ITERATIONS REACHED" file
should do. You'd be getting the I=2, too, because there's no
multi-line match with a back-reference here.


If the file structure were clearer we could probably use an
awk script to eliminate the the "successful" iterations number
from the output.


Cheers,
Tink
 
1 members found this post helpful.
  


Reply

Tags
pattern, print, search


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search values within multiple files line to line Chrizzieej Programming 5 09-26-2008 05:11 PM
delete a line containing a pattern and the next line of a text file powah Programming 3 01-31-2007 06:34 PM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 03:38 AM
Pattern search in a line jitz Linux - General 2 12-06-2003 05:50 AM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 02:56 PM


All times are GMT -5. The time now is 02:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration