The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Building Full-Text Search Applications with Oracle Text iBot Oracle Updates (RSS) 0 04-06-2008 02:10 AM
How to delete first 5 lines and last five lines in all text files ragavendran31 Shell Programming and Scripting 10 02-21-2008 04:58 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 07:24 AM
Moving next 2 lines contents to previous lines Amruta Pitkar Shell Programming and Scripting 8 04-26-2007 03:09 AM
search and retrieve previous line in file paulsew Shell Programming and Scripting 2 02-23-2007 05:04 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-05-2008
Registered User
 

Join Date: May 2008
Posts: 9
need to search text and output previous lines

I have a file (OMlog0) that is quite large, I need to find the line "Automatic Recharge Audit Process Finished" and output that line and the time stamp that occurs two lines previous. The line that I was using is "sed -n '/Automatic Recharge Audit Process Finished/,/No errors/p' /sn/log/OM* > ARe.out", but it doesn't give me the time stamp just the "Finished" line and the "No Errors" line.


excerpt from OMlog0:

+++ MRMCMAS 2008-05-05 09:56:10 ASRT #360578 cc1 LEAD >
REPT SPA=EPPSA24D
Automatic Recharge Audit Process Finished Correctly!
Errors found: No errors
END OF REPORT #360578++-

+++ MRMCMAS 2008-05-05 09:56:12 ASRT #360579 cc0 ACT >
** REPT NETWORK ASSERT=200, SPA=EPAY24D
Network Message Error - Invalid value BILLID in is41css7!t_answer
Subscriber ID = 4165551212
Call ID = IS41_1890072211480
Call Instance ID = 594903
Scenario Location=is41css7!t_answer_received
Trigger type =is41c_trty_t_answer
END OF REPORT #360579++-

+++ MRMCMAS 2008-05-05 09:56:12 ASRT #360580 cc0 ACT >
** REPT NETWORK ASSERT=200, SPA=EPAY24D
Network Message Error - Invalid value BILLID in is41css7!t_disconnect
Subscriber ID = 4165551212
Call ID = IS41_1890072211480


Desired output:

+++ MRMCMAS 2008-05-05 09:56:10 ASRT #360578 cc1 LEAD >
REPT SPA=EPPSA24D
Automatic Recharge Audit Process Finished Correctly!
Errors found: No errors
Reply With Quote
Forum Sponsor
  #2  
Old 05-05-2008
in2nix4life's Avatar
Registered User
 

Join Date: Oct 2007
Location: East Coast
Posts: 46
You can use 'grep' to print out the line you're looking, the two lines above it, and the line after it:

grep "Automatic Recharge Audit Process Finished Correctly" -B 2 -A 1 file.txt

+++ MRMCMAS 2008-05-05 09:56:10 ASRT #360578 cc1 LEAD >
REPT SPA=EPPSA24D
Automatic Recharge Audit Process Finished Correctly!
Errors found: No errors

Hope this helps.
Reply With Quote
  #3  
Old 05-06-2008
Registered User
 

Join Date: May 2008
Posts: 9
Thanks, but it doesn't seem to work for my system.

I am running Solaris 10 am when I do a man grep, the -A and -B options don't exist.

when I execute the command that you provided I get the following

grep: can't open -B
grep: can't open 2
grep: can't open -A
grep: can't open 1
grep: can't open file.txt

thanks,
Al
Reply With Quote
  #4  
Old 05-06-2008
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,260
I don't know Solaris, but if your grep supports the "-p" (paragraph) option you could use that. As it seems from the example the parts of the output you are interested in are delimited by blank lines (which is what defines "paragraphs" in the sense of the "grep -p").

I hope this helps.

bakunin
Reply With Quote
  #5  
Old 05-06-2008
Registered User
 

Join Date: Apr 2008
Posts: 16
If you do man on grep you will see that B and A are not supported operands
Reply With Quote
  #6  
Old 05-06-2008
Registered User
 

Join Date: May 2008
Posts: 9
I really appreciate everyone's help, but it Solaris doesn't seem to like the -p option either. Is there maybe another command either than grep that I should try?
Reply With Quote
  #7  
Old 05-07-2008
Registered User
 

Join Date: May 2008
Posts: 5
awk is best for such cases

Do something like this:

awk '/Automatic Recharge Audit Process Finished Correctly/ { \
print pre2 ; print pre1 ;print ;getline ;print ;next}\
{ pre1=$0; pre2=pre1}' /sn/log/OM* > ARe.out
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0