I'm running Ubuntu 22.04. My command
watch -d "sudo k0s kubectl get po && sudo k0s kubectl get po -n monitoring"
Outputs this:
NAME READY STATUS RESTARTS AGE
nginx-deployment-7fb96c846b-xh4vt 0/1 Pending 0 3m11s
nginx-deployment-7fb96c846b-2ndbm 0/1 Pending 0 3m11s
nginx-deployment-7fb96c846b-wlq57 0/1 Pending 0 3m11s
NAME READY STATUS RESTARTS AGE
kube-prometheus-stack-kube-state-metrics-8578c8f896-2svqh 0/1 Pending 0 2m58s
prometheus-kube-prometheus-stack-prometheus-0 0/2 Pending 0 2m58s
kube-prometheus-stack-grafana-779797848-mjp96 0/3 Pending 0 2m58s
kube-prometheus-stack-operator-dd6577db9-xkchz 0/1 Pending 0 2m58s
kube-prometheus-stack-prometheus-node-exporter-zkd8m 0/1 Evicted 0 44s
I want to exclude the column "AGE" from the highlighting ( -d ). Is there a way to do this?
Thank you!
CodePudding user response:
I understand that you need to extract particular fields from the output of the watch command, ran this on my Ubuntu and it works, you can add additional filters to modify as per your needs and build on the below.
Below looks at ls -ltr and extracts 1st,2nd and 3rd fields using awk and uses \t as the delimiter
>> watch 'ls -ltr|awk '\'{ print \$1 \"\\t\" \$2 \"\t\" \$3 \" \" }\'''
Every 2.0s: ls -ltr|awk '{ print $1 "\t" $2 "\t" $3 }' terminal: Thu Oct 13 15:29:20 2022
total 24316
drwxr-xr-x 2 xyz
drwxr-xr-x 3 xyz
you could also try NR command to extract N-1 fields(link below). https://stackoverflow.com/a/2961711/4739015