When I try to grep a subdomain having three dots("."), I am getting another fully qualified domain also that looks same as the sub domain but with hyphen("-") in the place of dot(".")
I just need the first result. Please help me...
grep abcd.efg.xyz.info /etc/named.conf
zone "abcd.efg.xyz.info" {
file "/var/named/abcd.efg.xyz.info.db";
zone "abcd-efg-xyz.info" {
file "/var/named/abcd-efg-xyz.info.db";
is there any other way? b'cos I am writing a script to search duplicate zone entries in the named.conf file. The script first makes a list of domains in the zone file and then searches for duplicate entries.
The problem is that the '.' is a wild-card in regular expressions and will be interpreted as any possible character. In your case you wanted the dot '.' specifically in which it needed to be escaped.
Ok.. I am almost near to my result. I decided to replace the whole dots in the file with \. and then search for the duplicates. Could you please tell me how to replace each . with \. in a file ?
I think you're misunderstanding. You don't need to modify the input file with the escaped dots (\.), just search for domains using the search term with escapes.
My pseudo code:
grep zone input_file | awk '{print $2}' | uniq (or pretty close to that)
for domain in "domain list from grep output"
do
sed to replace . with \. in $domain
grep -c escaped_domain from input file to get count
if count > 1
then
echo $domain is not unique, fix file
fi
done