![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 } |
|
||||
|
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")
}
Could you please help me for it |
|
||||
|
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
|
![]() |
| Bookmarks |
| Tags |
| gnu sed, nawk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|