EDIT: Some clarification. What I'm doing is I have a python script that will connect to my DNS servers and then run a bash script which is located in home to grep for all the A's in *something.com then grep for something else that I can't list out. After that I have either the 1st or 2nd parts of what I listed below run. The results from that get saved on a file on my computer.

It looks like this:

grep "A" *something.com | grep <something> | awk/sed <either the first or 2nd example>

The 1st script will give me

something.something.com:DNSentry    IP


DNSentry   IP

What I need is to make it looks like this.

DNSentry.something.something.com    IP

I've been trying to finish a script that will generate a DNS report. So far I have two ways of doing this and the results are this. Currently I have a long string of greps, awk and sed.

When using the string from this post I'm able to generate this. Generate CSV/TXT file from named zone file

org1.com:entry1       IP
org1.com:entry2       IP
org2.com:entry1       IP
org2.com:entry2       IP

I also have a script that can generate this by using this:

grep <pattern> | awk -F: '{if ($1 != last) {print "";print $1; last = $1} print $2}' | sed "s/A//"

I'm getting close with what I need but when I try and add the org.com to the line it will place it directly after the IP instead of the entry.

entry1        IP
entry2        IP

entry1        IP
entry2        IP


What I need to get is for the output to look like this

entry1.org1.com    IP
entry2.org1.com    IP

entry1.org2.com    IP
entry2.org2.com    IP
  • This is not a script-writing service. You should show us what you tried, where you failed, that you made an effort. – MariusMatutiae Aug 3 '16 at 17:07
  • Sorry I'm new to posting here. I've been beating my head against a wall trying to do this and learn as I go. In the future I'll be more clear in what I have done, failed and such. – Gurney Aug 3 '16 at 17:39

Not perfect or bulletproof, but maybe this gives you a start:

awk '/A/{print $1"."FILENAME"\t"$NF}' *something.com

that means, match lines from file with 'A' in the line, and print the FILENAME, the hostname of the record and the IP address.

  • Thank you for the reply! Where would I plug this into? I can't list out what the orgs are but they are the file names and have multiple .'s in them. My 1st grep is grep "A" *org.com – Gurney Aug 3 '16 at 16:57
  • I am confused. I've read like 20 times or so your question and still dont get it 100% what you want to do. Can you re-edit your question to be a little more specific plz ? Where did you do your first grep filter ? In a folder ? In a file ? If you can edit your initial question, perhaps it would make more sense for me or others. – ebal Aug 3 '16 at 17:01
  • Updated my post. I hope it helps clear stuff up – Gurney Aug 3 '16 at 17:21
  • I've just reedit my answer. does that makes more sense to you? – ebal Aug 3 '16 at 17:26
  • HUGE HELP! I can def take it from here and finish this up. Thanks a ton! – Gurney Aug 3 '16 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.