The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 05: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 07:58 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Moving next 2 lines contents to previous lines Amruta Pitkar Shell Programming and Scripting 8 04-26-2007 06:09 AM
search and retrieve previous line in file paulsew Shell Programming and Scripting 2 02-23-2007 08:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-05-2008
grinds grinds is offline
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
  #2 (permalink)  
Old 05-05-2008
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
  
 

Join Date: Oct 2007
Location: East Coast
Posts: 58
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.
  #3 (permalink)  
Old 05-06-2008
grinds grinds is offline
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
  #4 (permalink)  
Old 05-06-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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
  #5 (permalink)  
Old 05-06-2008
Tirmazi's Avatar
Tirmazi Tirmazi is offline
Registered User
  
 

Join Date: Apr 2008
Location: Maryland, USA
Posts: 50
If you do man on grep you will see that B and A are not supported operands
  #6 (permalink)  
Old 05-06-2008
grinds grinds is offline
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?
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0