O'Reilly logo

Python 2.6 Text Processing Beginner's Guide by Jeff McNeil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - suppressing portions of a match

In this example, we'll write a simple grammar for parsing a BIND DNS configuration file. In our regular expressions chapter, we learned out to process a zone file. In this example, we'll extract data from a /etc/named.conf file using PyParsing.

  1. First, we'll create some input data. Create a file named named.conf and copy in the following data. This example leaves off the values found in a named.conf options section for brevity.
    zone "example01.com" IN {
    	type master;
    	file "example01.com.dns";
    	allow-update { none; };
    };
    zone "example02.com" IN {
    	file "example02.com.dns";
    	type master;
    	allow-update { none; };
    };
    
  2. Now, create a Python script named conf_parse.py and enter the following code listing:
    import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required