I am trying to obtain a list of hosts from this influxdb query:
$ influx -database "collectd" -execute "SHOW TAG VALUES WITH KEY=host"
The output is something like:
name: system
key value
------------
host foo.tld
host bar.tld
name: mem
key value
------------
host foo.tld
host bar.tld
...
Currently, I am using awk
like this:
$ db-query | awk '/^host/ && !a[$2]++ { print $2 }'
This works when using shell sh
and returns only the list of unique hosts, for example:
foo.tld
bar.tld
But when using csh
shell I get this error:
a[: Event not found.
Any idea how to achieve this being portable in both sh
and csh
shells?
Try escaping any/all !
chars like \!
The csh
interprets the !
char as events in the command history.
The most common "events" used are !!
(previous line), and !$
(last word in previous line), but there are a million more.
I'm surprised you're getting that error msg, as I thought csh honored single-quotes.(but apparently not;-) ).
IHTH