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 > 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
How to delete first 5 lines and last five lines in all text files ragavendran31 Shell Programming and Scripting 10 02-21-2008 07:58 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
Delete lines containing text with sed umen Shell Programming and Scripting 2 08-01-2006 04:24 AM
Delete blocks with no data.. mgirinath Shell Programming and Scripting 1 01-28-2006 06:33 PM
Delete specific lines in a text file dniz High Level Programming 9 08-08-2005 08:30 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 12-19-2007
nrbhole nrbhole is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 18
Delete blocks of lines from text file

Hello,

Hello Firends,
I have file like below. I want to remove selected blocks say abc,pqr,lst. how can i remove those blocks from file.

zone abc {
blah
blah
blah }

zone xyz {
blah
blah
blah }

zone pqr {
blah
blah
blah }

zone lst {
blah
blah
blah }

zone bzs {
blah
blah
blah }
  #2 (permalink)  
Old 12-19-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
if your sed has the -i option:
Code:
sed  -i  '/zone pqr/,/}/d' newfile
  #3 (permalink)  
Old 12-19-2007
nrbhole nrbhole is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 18
Thanks Yogesh
I have almost 3000 blocks in this file. I have another list file which contain list of zone names e.g. pqr,abc,bzs.
I am using awk to run your sed command for each zone in list file

Code:
{
   zonename = $1
   sedcmd = "sed '/" zone zonename "/,/}/d' named.backup > named.backup.test"
   printf "Command: %s\n", sedcmd
   system(sedcmd)
   system("mv named.backup.test named.backup")
}
I think it's possible to optimize above coding. It's possible to remove system("mv named.backup.test named.backup") with some change.
Could you please help me for it
  #4 (permalink)  
Old 12-19-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
have you checked if -i option is supported in your sed?
  #5 (permalink)  
Old 12-19-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
awk

Hi,
Please try follow one.

One concern, i am not sure what will be content of all your blah blah. If they will cover all the content, maybe will cause some conflict with the code. Anyway, please try it, if any problem, please post it. Maybe all of us here can help you to solve it.

code:
Code:
sed '/^$/d' a > a.tmp
nawk 'BEGIN{
FS="\r"
RS="}\r"
a="abc"
b="pqr"
}
{
if ($1=="" && index($2,a)==0 && index($2,b)==0)
	print $0
if ($1!="" && index($1,a)==0 && index($1,b)==0)
	print $0
}' a.tmp
rm a.tmp
Closed Thread

Bookmarks

Tags
gnu sed, nawk

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:58 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