fix a txt file using perl or awk etc....

Hi Folks,

I require your help please.

I have a named.conf file that needs to be slightly reformatted.

The file has lots of comments on the first 40 or lines which is fine. But I need the important entries to be formatted slightly different.

The stuff looks like this: (( each entry on one line ))

zone "r1.fs.xx.us" in { type master; file "named.fwd.r1"; forwarders { }; allow-update { key ft.dhcp.ddns.key.; };};

zone "0.7.166.in-addr.arpa" in { type master; file "named.rev.0.7.166"; forwarders { }; allow-update { key ft.dhcp.ddns.key.; };};

I need it to be re-written to looks like so:

zone "r1.fs.xx.us" {
      type master;
file "named.fwd.r1";
forwarders { };
allow-update { key fs.dhcp.ddns.key.; };

};

zone "0.7.166.in-addr.arpa" {
      type master;
file "named.rev.0.7.166";
forwarders { };
allow-update { key fs.dhcp.ddns.key.; };
};

Would someone out there be so kind is to write some sort of perl script or shell script to make this happen please?

Thanks
LVL 1
richsarkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
while( <DATA> ){
s/\{(.*)}/{\n   $1\n}/ && s/((?:\{[^}\n]*}|.)*?;\s)/$1\n/g;
print;
}
__DATA__
zone "r1.fs.xx.us" in { type master; file "named.fwd.r1"; forwarders { }; allow-update { key ft.dhcp.ddns.key.; };};

zone "0.7.166.in-addr.arpa" in { type master; file "named.rev.0.7.166"; forwarders { }; allow-update { key ft.dhcp.ddns.key.; };};
0
richsarkAuthor Commented:
Hi ozo ,

Thanks for your response . Just to be on the same page. I should create a script named convert.pl in that file te contents will be:

while( <DATA> ){
s/\{(.*)}/{\n   $1\n}/ && s/((?:\{[^}\n]*}|.)*?;\s)/$1\n/g;
print;
}

To run this I would type:

Convert.pl input_file output_file > final.conf

Does that sound right?

Thank you.
0
ozoCommented:
If you run it like that, you would use <> instead of <DATA>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

richsarkAuthor Commented:
Right.. I caught that right after I submitted.

Will try it and report back.

Thanks ozo
0
richsarkAuthor Commented:
Hi Ozo,
I ran it, but seem to get a format issue

$ ./convert.sh r1_named.conf

./convert.sh: line 1: syntax error near unexpected token `)'
./convert.sh: line 1: `while( <> ){'

Contents are:

while ( <> ){
s/\{(.*)}/{\n   $1\n}/ && s/((?:\{[^}\n]*}|.)*?;\s)/$1\n/g;
print;
}
0
richsarkAuthor Commented:
I got it

did on the command line

perl convert.sh r1_named.conf
0
richsarkAuthor Commented:
Fantastic help !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.