Reputation: 2071
I'm trying to extract DNS PTR records out of a Microsoft zone, so that I can stage them to import them into a BIND zone. I have all the reverses, and they are in the following format:
1.0.0.10.in-addr.arpa. 1200 IN PTR my.long.domain.net.
22.0.0.10.in-addr.arpa. 1200 IN PTR your.long.domain.net.
33.0.0.10.in-addr.arpa. 1200 IN PTR our.long.domain.net.
What I am trying to do is extract the initial octet (in this case, the 1, 22, and 33 out of each line - at the beginning), but then I want to remove everything else, all the way to the "PTR" item. I then want to keep the "PTR" item as well as the actual reverse (for ex. my.long.domain.net. So, my guess would to use sed and the output that I want to end up with (using the example from above), would be:
1 PTR my.long.domain.net.
22 PTR your.long.domain.net.
33 PTR our.long.domain.net.
Is this something sed can do and how would I go about doing that? I'm by far any sed expert.
Thanks in advanced!
Upvotes: 0
Views: 236
Reputation: 58420
This might work for you (GNU sed):
sed -r 's/\..*(\sPTR)/\1/' file
Upvotes: 2
Reputation: 4935
I think this does what you want:
sed 's/\s\{1,\}/ /g;s/\([^.]*\).*PTR /\1 PTR /;s/^\(........\) */\1/'
Some of that is just to get the spacing you show in your desired output, if all you wanted were single spaced fields this would do:
sed 's/\s\{1,\}/ /g;s/\([^.]*\).*PTR /\1 PTR /'
Upvotes: 0