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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pattern match in each line and capture it question bsandeep_80 UNIX for Advanced & Expert Users 16 04-02-2008 02:39 PM
Concatenating multiple lines to one line if match pattern phixsius Shell Programming and Scripting 13 01-24-2008 11:02 PM
return the previous line user_prady Shell Programming and Scripting 12 12-18-2007 07:37 AM
sed - Replace Line which contains the Pattern match with a new line kousikan Shell Programming and Scripting 2 03-24-2007 07:24 AM
match a pattern, print it and the next line nymus7 Shell Programming and Scripting 4 07-29-2005 12:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-26-2006
braindrain braindrain is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 67
return previous line for pattern match

Hi,

Need some idea on file processing, I have file like below,

Code:
Processing al sources ...
...No value found : 
CHECK. 
Completed comparing all  sources.
Comparing schedulers...
Processing al targets ...
...No value found :
From above I need to extract the line where "No value found" is available, which is simple, but I also wanna print the line before i.e
Code:
Processing al sources ...
...No value found : 
Processing al targets ...
...No value found :
Can sometell me how to go about this ?

Thanks
  #2 (permalink)  
Old 06-26-2006
vino's Avatar
vino vino is online now Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
You never mentioned your OS. If you have GNU grep, the use

Code:
grep -B 1 "No value found" file
  #3 (permalink)  
Old 06-26-2006
thestevew thestevew is offline
Registered User
  
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
If your grep has no -B (Aix hasn't) then:
Code:
sed -n -e 'N; /No Value Found/p' yourfile.txt
cheers
  #4 (permalink)  
Old 06-26-2006
braindrain braindrain is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 67
sorry guys, didn't give enough information,this is in suse linux,

sed -n -e 'N; /No match/p' $1 worked perfect.... thanks..

Last edited by braindrain; 06-26-2006 at 11:40 AM..
  #5 (permalink)  
Old 12-08-2008
ysrinu ysrinu is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 15
Hi,
i tried
sed -n -e 'N; /No Value Found/p' yourfile.txt

but it only prints the previous line for the first match only.
thereafter only matching lines are printed and not their previous lines.

Thanks,
-srinivas yelamanchili
Closed Thread

Bookmarks

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 12:59 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