Script question for BIND
I need to or want to delete BIND DNS entries that are in File1 that match A records in File2. If the DNS entry has multiple records associated to it in File2, those need to remove too.
File1 Code:
car.example.com File2 Code:
car A 192.168.10.1 After the removal, I need or would like to add back new DNS entries into File2. Code:
car.example.com A 172.10.1.12 Code:
grep -vwf file1 file2 Code:
grep -f <(cat file1 | sed 's/^/^/' ) file2 |
Try this:
To get the repeated domains list: Code:
cut -d ' ' -f 1 file1 file2 |sort |uniq -d Code:
grep "[0-9\.][0-9\.]*, [0-9\.][0-9\.]*" file2 |
Instead of the grep I suggested above, better just:
Code:
grep "," file2 bike.example.com 192.168.10.5, trek.example.com |
@OP as a start, please read this topic: https://www.linuxquestions.org/quest...gs-4175464257/
|
Quote:
Thanks for your reply. I realized that my file2 example wasn’t properly laid out as for what I’m dealing with. I updated it just now. |
Quote:
|
Code:
grep -Fvwf <(cut -d. -f1 file1) file2 |
What about this?
Code:
1) joins all lines of the same record in a temporary file (awk line) 2) reads file1 into a string and prepares the grep arguments: -e "^car" -e "^truck" -e "^bike" 3) writes all records without car truck bike recovering the newlines into the file out 4) writes the removed records into the file deleted 5) removes temporary file replace ---newlinemark--- with something you will not find in any record |
Quote:
interesting approach. Thanks! I did notice that it did remove more than I wanted though. anything that started with car or truck or bike removed. example: car1, car300, bikes, etc. Im trying to just remove the ones that are named exactly the same, nothing more. |
You are wellcome
Quote:
try this code Code:
awk '{ |
Im kinda of newbie when coming to scripting ... I know some but no way an expert at it.
I could use some help on how to remove a host entry that could have (3) IP addresses then replace it with the proper (1) IP address. I can remove 1 IP address but not if it has multiple. I tried multiple ways and confused myself and not even sure which way was proper to remove one. A little guidance would be much appreciated. Thank you! |
Sorry, I don't get what your problem is. You're matching the records not against IP addresses, but against host names, right? So what if a host has multiple IP addresses? It will be matched anyway.
E.g. Code:
$ dig de.archive.ubuntu.com|grep ^\\w It would be nice if you provided an example of what you tried to do, and what didn't work. |
Quote:
good example. how would you remove all those entries at once? I think if I dig for it first then remove it, that may do the trick. |
Quote:
Well, I was of impression that your zone file is like in the Dyn example where the host name is repeated for each IP address. However, if it's more similar to the example in RFC 1035 then I'd use range patterns: Code:
sed '/^VENERA\>/,/^$/d' Code:
awk '/^VENERA[ \t]/,/^$/{next}1' |
\t in a character set is not standard.
I would go for Code:
awk '/^VENERA[[:blank:]]/,/^$/{next}1' Code:
awk '$1=="VENERA"{d=1} !d; !NF{d=0}' |
Quote:
|
All times are GMT -5. The time now is 07:35 AM. |