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
print all even lines of a txt file ajp7701 Shell Programming and Scripting 1 04-18-2008 12:17 AM
How to print only lines in between two strings using awk jisha Shell Programming and Scripting 4 01-11-2008 04:13 AM
How to print all lines that has exactly 3 occurences of digit 4 using grep? sivasai83 Shell Programming and Scripting 3 01-31-2007 02:21 AM
How to print number of lines with awk ? maheshsri Shell Programming and Scripting 1 11-18-2005 02:19 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 06-25-2008
jakSun8 jakSun8 is offline
Registered User
  
 

Join Date: Dec 2007
Location: Gotham City
Posts: 59
Print lines after grep

Hi all,

I need help in following scenario. I have a file with about 10,000 lines. There are several lines which have word "START" (all upper case) in them. I want to grep line with word "START" and then do the following
1. Print the line number having word "START"
2. Print the next 11 lines.

Any help is appreciated.
JAK
  #2 (permalink)  
Old 06-25-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,441

Code:
awk '/START/{f=NR;print NR}{if(NR > f && NR < f+12) print}' data.file

  #3 (permalink)  
Old 06-25-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
Another one:

Code:
awk 'c&&c--;/START/{print NR;c=11}' file

Use nawk or /usr/xpg4/bin/awk on Solaris.
  #4 (permalink)  
Old 06-25-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,441
Quote:
Originally Posted by radoulov View Post

Code:
awk 'c&&c--;/START/{print NR;c=11}' file
That's nice
  #5 (permalink)  
Old 06-25-2008
jakSun8 jakSun8 is offline
Registered User
  
 

Join Date: Dec 2007
Location: Gotham City
Posts: 59
Thanks for the reply. I really appreciate it.

JAK
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 11:29 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