Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I believe both you and the parent meant to escape the dot, as to only return lines with a dot in them:

     dig example.com | awk '/\./ && !/^;/ {print $5}'
If it isn't escaped it'll just match on everything.

If matching everything was intended then you don't need it at all:

     dig example.com | awk '!/^;/ {print $5}'
Will strip out the lines beginning with a semi-colon.

However, parsing the output of `dig` this way is not needed. It can be ran to only return the answer, for example:

     dig +noall +answer example.com
Or if you just want the IP for that record:

     dig +short example.com


I was actually just using `grep .` to discard empty lines. The `grep -v '^;'` would have only left lines with answers after it discarded lines starting with `;`. That and the empty lines.

I could have combined `grep -v '^;'` and `grep .` as a nice simple `grep '^[^;]'`


Ahh. I was working from memory, I forgot about the empty lines it returns. That's what I get for replying from my phone. :)

However, it's still better to just have the `dig` command return only the necessary information via the +short or +noall +answer flags, rather than parsing the full output.


Remind me again where this weird syntax came from for passing arguments?


- is allowed in domains


dash is only allowed in the middle. labels can't start or stop with it. so it wouldn't affect the command arguments.

    The labels must follow the rules for ARPANET host names.  They must
    start with a letter, end with a letter or digit, and have as interior
    characters only letters, digits, and hyphen.  There are also some
    restrictions on the length.  Labels must be 63 characters or less.
https://www.ietf.org/rfc/rfc1035.txt

it's more likely that in the late 90s they just made up their own argument parsing that they liked and the application has just used that ever since.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: