【问题标题】:Bash : Remove everthing before special caracterBash:删除特殊字符之前的所有内容
【发布时间】:2022-09-22 22:02:49
【问题描述】:

我有一个大的 json 文件,其中包含要在每个值中修改的文本。如果我们看第一个条目,它看起来像:

$ cat description6fr.json | jq \'.[0].fr\'
Something\\nSomethings\\n\\nSomething\\n\\nSomething

如何在第一次之前削减所有内容\\n\\n?我确实用 sed 和 awk 尝试了很多东西,但欢迎提供帮助。谢谢!

    标签: bash awk sed


    【解决方案1】:

    您可以使用split() 的字符串:

    jq '.[0].fr | split("\n\n") | first' description6fr.json
    
    "Something\nSomethings"
    

    JqPlay demo

    【讨论】:

      【解决方案2】:

      您可以使用 index 找到匹配项,然后对其进行切片:

      jq '.[0].fr | .[index("\n\n") + 2:]' description6fr.json
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-23
        • 1970-01-01
        • 1970-01-01
        • 2021-06-26
        • 2016-05-07
        相关资源
        最近更新 更多