How to extract the first column in grep command and pass to next command in linux cmd?

935 views Asked by At

I using cmder in windows - kind a bash with command prompt.

In this cmder I run a command:

kubectl get pod

and I get those results:

NAME                                READY   STATUS      RESTARTS   AGE
alpine-d4c458d59-4xxxxsb            1/1     Running     0          31d
cron-my-ecr-1618xxxx-hdcjq          1/1     Running     0          16h
cron-ecr-renew-1618xxxx800-zdxps    1/1     Running     0          10h

I want to run another command base on the result:

kubectl logs cron-my-ecr-1618xxxx-hdcjq

My question is how I run one command instead of two and avoid copy-paste?

What I was able to do is run by grep:

kubectl get pod | grep cron-my-ecr

Which give me the one row of result:

cron-my-ecr-1618xxxx-hdcjq          1/1     Running     0          16h

But how I extract the first column and pass it to the next command?

1

There are 1 answers

0
Arun Karoth On

You could do something like this

kubectl get pod | grep cron-my-ecr | awk '{print $1}';kubectl describe po $(!!)