bash - 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 但空间分隔的长度不同。有什么建议么?
解决方案
您可以使用此管道获取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/%'
推荐阅读
- npm - 无法在 Mac 上使用 NPM init 创建 Package.JSON 文件
- c++ - 使用 std::all_of 和 boost::irange 来获取循环索引
- vb.net - 如何删除表单关闭时正在运行的exe
- html - 使用 CSS 选择器定位动态 CSS 元素
- javascript - 两个 jquery 下拉菜单在创建页面上工作,但不在编辑页面上
- sql - 在加入另一个表时,如何在每个案例的案例语句中给出 where 条件
- html - 将 AWS 中使用的某些百分比替换为 $25 的编码名称是什么
- sql-server - 如何在 SQL Server 中创建以 PRIMARY 为列名的表?
- python - pysnmp 自定义 MIB-Walk 失败
- html - 如何仅显示图像名称而不是完整的图像路径