【问题标题】:Bash extract stringBash 提取字符串
【发布时间】:2022-10-19 16:27:11
【问题描述】:

有没有办法提取这个字符串? libtirpc-common:arm64 (1.3.1-1, 1.3.1-1+deb11u1), libtirpc3:arm64 (1.3.1-1, 1.3.1-1+deb11u1), libtirpc-dev:arm64 (1.3.1-1, 1.3.1-1+deb11u1)

我只想得到libtirpc-common:arm64 (1.3.1-1, 1.3.1-1+deb11u1)

【问题讨论】:

  • 请添加到您的问题中(无评论):您搜索了什么,找到了什么?你尝试过什么,它是如何失败的?
  • 你如何确定要提取什么?第一个逗号分隔的元素?包含common的元素?
  • 它应该在括号后的逗号后分隔。

标签: bash


【解决方案1】:

使用 awk:

awk -F '),' '{ printf "%s)",$1 }' <<< "libtirpc-common:arm64 (1.3.1-1, 1.3.1-1+deb11u1), libtirpc3:arm64 (1.3.1-1, 1.3.1-1+deb11u1), libtirpc-dev:arm64 (1.3.1-1, 1.3.1-1+deb11u1)"

将字段分隔符设置为“)”,然后打印第一个字段,后跟 )

【讨论】:

    猜你喜欢
    • 2012-07-06
    • 2023-03-20
    • 1970-01-01
    • 2021-10-31
    • 2015-04-26
    • 2019-06-22
    相关资源
    最近更新 更多