"awk" a value from irregular output by column name
3
votes
2
answers
560
views
I'm writing a bash script that uses
helm history
(Kubernetes tool) command to get the last revision number of my release. The output for the command is like this:
helm history release
REVISION UPDATED STATUS CHART DESCRIPTION
1 Mon Feb 27 12:46:10 2017 SUPERSEDED chart-solution-0.1.0-beta1 Install complete
2 Fri Mar 3 11:40:55 2017 SUPERSEDED chart-solution-0.1.0-beta1 Upgrade complete
3 Fri Mar 3 11:41:02 2017 DEPLOYED chart-solution-0.1.0-beta1 Upgrade complete
The expected result is to return only the number 3
(last value) from the REVISION
column. I can do that for now using:
helm history release | awk -v col=REVISION 'NR==1{for(i=1;i1{print $c}' | tail -n 1
3
However, the "column" UPDATED
is irregular (space separated items), and the above command only works because the REVISION
column comes before UPDATED
.
If in future versions the helm history
command change the order of columns, things can get messed.
A simple example is if I a try to get the last value using the column STATUS
, which comes after UPDATED
:
helm history release | awk -v col=STATUS 'NR==1{for(i=1;i1{print $c}' | tail -n 1
Mar
There is a way to get the correct last REVISION
value even if the column order changes?
Asked by Eduardo Baitello
(656 rep)
Mar 3, 2017, 12:25 PM
Last activity: Mar 4, 2017, 10:53 PM
Last activity: Mar 4, 2017, 10:53 PM