Given a list of readings in the following format:
1 1 0 0 2 3 23101 23101 0 0 2 0 5 2 0 0
1 1 0 0 2 2 23104 23104 0 0 1 0 5 1 0 0
What would be an approriate (and clean !) way to map them to their labels (the labels are not in a fixed format, I just know from the documentation that column 1 maps to X, column 2 maps to Y etc. etc.).
The output is going into a text file for prometheus
to read, so the desired format would be a two line format as follows:
# TYPE label_goes_here counter
label_goes_here value_goes_here
Ideally I would like this to use sh
or ksh
native tools. perl
is ok too as its widely installed as default, unlike, say, python
.
Edit to add example:
Given:
1 1 0 0 2 3 23101 23101 0 0 2 0 5 2 0 0
We could expect the output to look like:
# TYPE name_of_label_1 counter
name_of_label_1 1
# TYPE name_of_label_2 counter
name_of_label_2 1
# TYPE name_of_label_3 counter
name_of_label_3 0
etc.
etc.
# TYPE name_of_label_16 counter
name_of_label_16 0
echo "1 1 0 0 2 3 23101 23101 0 0 2 0 5 2 0 0" |awk '{print "name_of_label_1 "$1"\nname_of_label_2 "$2"\nname_of_label_3 "$3"\nname_of_label_4 "$4"\nname_of_label_5 "$5"\n"}'
, but I don't get the significance of the comments or counter. – bitinerant Sep 21 '19 at 17:03awk
is your best choice if you want a portable script - it's almost certain to be on every unix-like system in existence. – cas Sep 22 '19 at 03:33