[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

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
0
richsark
Asked:
richsark
  • 5
  • 2
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now