in reply to Re^8: Deleting lines from named.conf file
in thread Deleting lines from named.conf file

Taking exactly your input file
zone "foo.com" { type master file path to the zone }; zone "blah.com" { type master file path to the zone }; zone "bar.com" { type master file path to the zone };

and running the script provided

qwurx [shmem] ~ > perl zonedel.pl please enter the domain name: foo.com

I get as result

zone "blah.com" { type master file path to the zone }; zone "bar.com" { type master file path to the zone };

Yes, it starts with a blank line, but the zone definition is gone. What the heck did you run? Is it really that difficult to suppress blank lines? I'm running out of advice for you.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^10: Deleting lines from named.conf file
by firewall00 (Acolyte) on Nov 11, 2007 at 02:51 UTC
    i have tried to eliminate the blank line that created so i but this line before the print line
    next if /^\s*$/;

    but this suppress any new line in the whole file
    i think i need to provide something like unless /\s/; after printing the line for this zone only
      If you always have your zone definitions separated with blank lines, but no blank lines in the zone blocks, the task is even easier - read and write the file in paragraph mode:
      #!/usr/bin/perl -w -ni.bak -00 use strict; BEGIN { local $/ = "\n"; print "please enter the domain name: "; use vars qw($targetdomain); chomp ($targetdomain = <STDIN>); } print unless /^zone\s+"$targetdomain"/;
      Call that script with the zone file as argument, e.g.
      perl zonedel.pl /home/blackice/hello

      It will create a backup of the file. For the switches after '#!/usr/bin/perl' see perlrun.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        thanks mr shmem you were surly right but i was having some mistakes . thanks for your great support

        Really thanks for you further assistance


        but i used what you have said "paragraph mode" but there is also still a 2 blank lines between the zone assume that i have deleted a zone in the middle of 2 zones
        the out is still just like that
        zone "foo.com" { type xxxxx path xxxxx info xxxxx }; zone "blah.com" { type xxxxx path xxxxx info xxxxx }; zone "bar.com" { type xxxxx path xxxxx info xxxxx };
        after running zonedel.pl with your new optimization
        zone "foo.com" { type xxxxx path xxxxx info xxxxx }; #2 blanks still created # zone "bar.com" { type xxxxx path xxxxx info xxxxx };

        i have read perlrun and i didnot find any switch that i can enable to eliminate the the blank lines created
        what do you think about providing a line that makes a shifted up move after delete zone
        or after deletion do
        s/\n//;
        to eliminate the created blank line so i will always have a one blank line between the two zones
        and thanks again for your further support
Re^10: Deleting lines from named.conf file
by firewall00 (Acolyte) on Nov 11, 2007 at 00:47 UTC
    thanks u are right and sorry for misunderstanding
    i want to ask you also about $comment variable if you wouldn't mind i want to understand what is itis value here itis as i asked you before
    at the end i hope to be like you in a day
    and thanks for every thing