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
grab next consecutive line or lines wisher115 Shell Programming and Scripting 1 12-07-2006 08:01 AM
Cutting the top two lines, and also charachters below. jalge2 UNIX for Dummies Questions & Answers 5 08-02-2005 03:59 PM
Appending Consecutive lines pondlife Shell Programming and Scripting 8 08-13-2004 06:36 AM
Cutting n consecutive lines from a file... Vishnu UNIX for Dummies Questions & Answers 2 10-18-2002 11:49 AM
Cutting lines out using sed I presume. cfoxwell UNIX for Dummies Questions & Answers 5 01-08-2002 12:13 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-04-2008
raghin raghin is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 1
need help cutting consecutive lines with sed or awk

HI All,

I want to cut 5 lines after a pattern using sed or awk. can any one tell me how to do it ?
  #2 (permalink)  
Old 06-04-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 167

Code:
$ cat file.txt
AA
BB
CC
DD
EE
FF
GG
HH
II
$ sed -n '/^DD/{p;n;p;n;p;n;p;n;p;}' file.txt
DD
EE
FF
GG
HH

or 

If you don't want the pattern,
$ sed -n '/^DD/{n;p;n;p;n;p;n;p;n;p;}' file.txt

//Jadu
  #3 (permalink)  
Old 06-04-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342

Code:
awk '/pattern/{n=5;next}n{print;n--}' file

Regards
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 09:55 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