【问题标题】:How to extract the first column in grep command and pass to next command in linux cmd?如何提取 grep 命令中的第一列并传递给 linux cmd 中的下一个命令?
【发布时间】:2021-04-14 04:21:53
【问题描述】:

我在 Windows 中使用 cmder - 一种带有命令提示符的 bash。

在这个cmder中我运行一个命令:

kubectl get pod

我得到了这些结果:

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

我想根据结果运行另一个命令:

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

我的问题是我如何运行一个命令而不是两个命令并避免复制粘贴?

我能做的是由 grep 运行:

kubectl get pod | grep cron-my-ecr

这给了我一行结果:

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

但是我如何提取第一列并将其传递给下一个命令?

【问题讨论】:

  • 您可以使用 cut、awk 或 sed 来完成。可能还有其他人,但首先想到的是这些。

标签: linux windows cmd cmder


【解决方案1】:

你可以这样做

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2013-05-18
    • 1970-01-01
    相关资源
    最近更新 更多