LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2007, 06:51 PM   #16
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908

Please post the relevant code segment. I cannot guess what you have and why it does not do what you want.

--- rod.
 
Old 10-05-2007, 08:08 PM   #17
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
Code:
#!/usr/bin/perl -w 

use strict;

print " please enter the domain name: ";

my  $targetdomain = <STDIN>;

chomp $targetdomain;

my  $file = "/home/blackice/hello";


open HAN,$file || die "error opening file: $!";

my @array = <HAN>;

close(HAN);

      foreach my $i ( 0 .. $#array ){
  
         if( $array[$i] =~ m/^zone\s+"$targetdomain"/ ){
  
            $array[$i-1] = '' unless $i == 0; #first line of file condition
  
            for my $n (0 .. 5) {
  
                $array[$i+$n] =  '//' . $array[$i+$n];
  
            }
  
         }
  
      }

open HAN, ">$file";

print HAN @array;

close(HAN);
here is the code but i have last problem when i run this code the output like that

Quote:
//zone "mydomain.com" {
//type master;
//file "/path/to/zone/mydomain.com";
//notify yes;
//}
//
i want the first empty line commented also without affecting the other lines cuz in my output the first line shifted and commented to the first line in the file

itis now done thanks for alll and for your great support



Quote:
foreach my $i ( 0 .. $#array ){

if( $array[$i] =~ m/^zone\s+"$targetdomain"/ ){

$array[$i-2] = '' unless $i == 0; #first line of file condition

for my $n (-1 .. 5) {

$array[$i+$n] = '//' . $array[$i+$n];

}

}

}

Last edited by adam_blackice; 10-05-2007 at 09:47 PM.
 
Old 11-07-2007, 08:01 AM   #18
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
If it's not too late -- I just found this thread -- or too heretical , would not the following do what you want?:
Code:
#! /bin/bash
F="bind"
read -p " please enter the domain name: " X
sed -i '\#^zone .*'$X'#,\#^}#s,^,//,;\#//}#N;s,\n *,\n//,' $F
I named my test file bind & put your "hello" contents in it followed by 2 blank lines, here is the output of my little script:
Quote:
//zone "mydomain.com" {
//type master;
//file "/path/to/zone/mydomain.com";
//notify yes;
//}
//
I think that's the same as your last post.

If my sed seems cryptic, it might help to know that I am using '#' as the delimiter for the address regexes & ',' as the delimiter for the replace regexes. Although I rarely see it, I believe Perl also has this feature.

If you were to use this, you might want to eliminate the "-i" (in-line) option & send the output to a different file instead, at least during testing.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: testing for blank lines Garda Programming 4 11-16-2006 07:39 PM
Perl and drawing lines Veteq Programming 2 11-27-2004 07:16 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration