lova February 2016

How to get second value of second column in output

I have an output like this:

NAME              CLUSTER_IP     EXTERNAL_IP   PORT(S)    SELECTOR                  AGE
docker-registry   172.30.131.5   <none>        5000/TCP   docker-registry=default   33m

Now I want to get the IP. Nothing else. I used awk but always got CLUSTER_IP with it too

result=$(oc get svc/docker-registry | awk '{print $2}')

Answers


Ed Morton February 2016

Just select the 2nd line:

result=$(oc get svc/docker-registry | awk 'NR==2{print $2}')


sat February 2016

You need to skip the header line. Like this:

result=$(oc get svc/docker-registry | awk 'NR!=1{print $2}')

Post Status

Asked in February 2016
Viewed 2,583 times
Voted 13
Answered 2 times

Search




Leave an answer