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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep and display few lines before and after melanie_pfefer SUN Solaris 13 02-19-2009 11:54 PM
grep/cat/more -- search in a txt file and display content from a specific "keyword" I-1 UNIX for Dummies Questions & Answers 4 02-21-2007 04:57 AM
display all lines shary Shell Programming and Scripting 3 02-17-2007 04:09 PM
display no of empty lines atticus Shell Programming and Scripting 5 03-22-2006 03:35 PM
display few lines of the file sharuvman UNIX for Dummies Questions & Answers 4 04-27-2004 08:14 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 08-17-2008
wangzosen wangzosen is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 7
display (ehco) 5 lines before and after find keyword

I like to display 5 lines before and after find some keywork (i.e. error).

Thanks in advance
  #2 (permalink)  
Old 08-17-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
grep -B 5 -A 5 keyword file ? not sure I understand your question.
  #3 (permalink)  
Old 08-17-2008
wangzosen wangzosen is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 7
Thanks for response. It is exactly what I want. Is it possible to have highlight or color code the keyword on output?
  #4 (permalink)  
Old 08-17-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
try --color=auto

grep -B 5 -A 5 --color=auto keyword file
  #5 (permalink)  
Old 08-17-2008
wangzosen wangzosen is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 7
Cool. You are the men and thank you for help.
  #6 (permalink)  
Old 08-17-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,092
hi, below one may put some light on your issue.


Code:
line=`sed -n "/$1/=" file`
echo $line
nawk -v l="$line" '{if(NR>=(l-1) && NR<=(l+1))
print
}' file

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 07:31 PM.


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