I am trying to get clean the file having domain names but they are not FQND (fully qualified domain names).
I have tried this script, but it is damn slow (For only 3 inputs taking more than 30 seconds):

for h in "bert" "ernie" "www.google.com"
    host $h 2>&1 > /dev/null
    if [ $? -eq 0 ]
        echo "$h is a FQDN"
        echo "$h is not a FQDN"

The input what I am trying to give is a big file containing the following:

example1.com .com

Where output should be only:


Hope the idea is clear. Can it be done with some sed, awk, or other scripting used by Ubuntu 16.04?

  • examplecom.de is an FQDN. – muru Feb 3 '17 at 6:10
  • @muru No if you use the above bash script you will come to know that examplecom.de is not FQDN – Jaffer Wilson Feb 3 '17 at 6:18
  • 1
    I don't care what your bash script does, but examplecom.de fits the definition of an FQDN. – muru Feb 3 '17 at 6:18
  • @muru But I do not want to have such domain. It is not valid. Don't you think the same? – Jaffer Wilson Feb 3 '17 at 6:24
  • 2
    What muru said. This script doesn't check if a string is an FQDN; it checks if the host succeeds a DNS lookup. – wjandrea Feb 3 '17 at 6:25

Your Answer

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

Browse other questions tagged or ask your own question.