469,935 Members | 1,924 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

Parse .yaml file and enter result into two separate files

I am starting work on a script that will parse a .yaml file and prep that for entry into two files. The two files will be BIND zone files.

the yaml data will look something like this:



This will need to be manipulated and entered into two zone files.

This is an example of what the data will need to be formatted like:

File one:

hostname1 A

( The A is usually the same )

File two:


( "IN PTR" will be the same among all entires to be added to the zone file)

The areas where i am having the most difficulty are How can i use python to do sed

This awk and sed shell script would work for file two first field "11".

ifconfig $1 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}' | sed / | cut -d "." -f4

maybe I should just use the

from subprocess import call
call(["ifconfig $1 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}' | sed / | cut -d "." -f4"])

Does this seem like the best option?

Also is this the best way to print to the end of a file for my scenario? I am assuming open with the append option.

open('file', "a") as FILE

I am unclear on how best to open the .yaml file grep it and then translate to print to the next file.

Jun 5 '13 #1
0 1183

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Shailesh Patel | last post: by
1 post views Thread by Newsgroup - Ann | last post: by
14 posts views Thread by Rob Meade | last post: by
reply views Thread by Meetee | last post: by
5 posts views Thread by AdrianH | last post: by
1 post views Thread by AdrianH | last post: by
6 posts views Thread by =?Utf-8?B?RGF2aWRN?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.