3 ms·
> dig google.com | grep -v '^;' | grep . | awk '{ print $5 }'` It wasn't really your point, but hopefully you'll forgive me sharing an equivalent one-liner, wi
by tux1968 3y ago
> dig google.com | grep -v '^;' | grep . | awk '{ print $5 }'`
It wasn't really your point, but hopefully you'll forgive me sharing an equivalent one-liner, without grep:
dig google.com | awk '/./ && !/^;/ {print $5}'
- redundantly 3y agoI 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
- knome 3y agoI 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 '^[^;]'`
- redundantly 3y agoAhh. 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.
- pests 3y agoRemind me again where this weird syntax came from for passing arguments?
- wbl 3y ago- is allowed in domains
- knome 3y agodash 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 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.
- deleted 3y ago[deleted]