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
URGENT: Script/Function needed to read text property files in block wise ysreenivas Shell Programming and Scripting 7 05-11-2009 04:08 AM
Delete a block of text delimited by blank lines when pattern is found gleu Shell Programming and Scripting 17 12-16-2007 11:30 PM
Deleting text block in file andre123 Shell Programming and Scripting 1 02-27-2007 01:17 PM
Delete lines containing text with sed umen Shell Programming and Scripting 2 08-01-2006 05:24 AM
how to delete away text in a file? forevercalz Shell Programming and Scripting 5 01-08-2006 10:28 PM

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 10-21-2005
toast toast is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 2
using sed(?) to delete a block of text

hello people,
i am trying to accomplish what i thought should be a simple task: find a token in a file and delete a number (let's say 25) of lines following the token.

in sed, i can't figure out how to do a relative address (i.e. something like /token/25dd to delete 25 lines) and in gnu grep, if i use the -A 25 option, it only works with a positive match, but not with -v

i suppose i could accomplish same by matching the number of open and closed parentheses (), since that's how the file is formatted, but i'm also not sure how to do that

any thoughts would be most welcome!

thanks in advance

ilya

P.S. for example

if the file contains:
===========
a: (
some text(more)
blah (blah)
)

b: (
another(word)
and stuff(gf)
)

===========

i would want to remove the 4 lines from a: to )
  #2 (permalink)  
Old 10-21-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
GNU sed supports this.

from the manual page
Quote:
addr1,+N
Will match addr1 and the N lines following addr1.
So....

sed '/^a:/,+3 d' filename

should do what you want.

Cheers
ZB
  #3 (permalink)  
Old 10-21-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Using awk...
Code:
awk '/^a:/{c=4};--c<0' file

  #4 (permalink)  
Old 10-23-2005
toast toast is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 2
your kung-fu is very strong!

thank you, thank you zazzybob and ygor!

In defence of my lack of RTFM: MANPATH on my solaris box! i got the solaris sed manpage, rather than the gnu one
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 02:34 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