Search code examples
linuxbashpipestderrdig

dig -x +short to file without STDERR


When I do: dig -x +short I get only the hosts output, but when doing dig -x <ip> +short > file.txt I get all the rubbish, as if it was not executed with +short.

I have tried:

dig -x <ip> +short 2>&1 > file.txt

also

dig -x <ip> +short 2>/dev/null > file.txt

But didn't work, Thank you


Solution

  • As @anubhava observed in a comment, ordering matters:

    dig +short -x "$ip"