首页 > 解决方案 > awk launchctl 输出和管道到另一个命令

问题描述

如何通过管道输出命令

gent$ launchctl list | grep 'com.apple.CoreSimulator.SimDevice'
9222    0       com.apple.CoreSimulator.SimDevice.B79F217D-5158-48BB-BA4C-7089CA29ACBB
$ launchctl list | grep 'com.apple.CoreSimulator.SimDevice' | awk -F '   ' '{print $2}'

预期产出

com.apple.CoreSimulator.SimDevice.B79F217D-5158-48BB-BA4C-7089CA29ACBB

我最终想将该输出提供给launchctl remove <output from above>

我一直在使用 awk 但空间分隔的长度不同。有什么建议么?

标签: bashshell

解决方案


您可以使用此管道获取service-name打印awk内容,然后将其输入xargs命令以使其运行为launchctl remove gui/501/<service-name>

launchctl list |
awk 'index($NF, "com.apple.CoreSimulator.SimDevice") {print $NF}' |
xargs -I % launchctl remove 'gui/501/%'

推荐阅读