7 ms·
>I don't know what the semicolons before the lines are supposed to convey but they're only making things confusing all of the lines that aren't part of the que
by knome 3y ago
>I don't know what the semicolons before the lines are supposed to convey but they're only making things confusing
all of the lines that aren't part of the query answer are prefixed with semicolons. so it's basically a comment character. presumably to ease processing of the data it spits out.
You know. So you can `dig google.com | grep -v '^;' | grep . | awk '{ print $5 }'` easily.
I can imagine people using it in a shell script 20 years and more ago to grab a list of IPs to do some domain's health check or whatever
Not that you would want to in any modern stack. obviously you'd just use dig's `+short` option :)
- jeroenhd 3y agoNow I just wonder what the double semicolons mean and why they're different from single semicolons :) It's fine, I can Google the answer, I just wished I didn't need to. I already know to use +short when I just want the result(s). I use it in a script to detect and resolve my Pihole's random freezes (by timing the lookup and rebooting the VM every time a lookup fails or takes longer than 200ms, janky but it works).
- dclowd9901 3y agoPerhaps there is info that would normally be present and isn’t, hence stacked semicolons.
- skrebbel 3y agoA precision engineering tool shouldn’t make its users guess like that.
- dclowd9901 3y agoTotally agree.
- deleted 3y ago[deleted]
- 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?
- 3y ago