【问题标题】:Parse output of mdimport using grep/awk/sed/etc. on macOS?使用 grep/awk/sed/etc 解析 mdimport 的输出。在 macOS 上?
【发布时间】:2021-02-20 09:58:11
【问题描述】:

我需要解析 mdimport(macOS 中的 Spotlight 相关工具)的输出

mdimport -t -d3 $file 

...将许多属性和值转储到标准输出,包括 kMDItemTextContent。

如何使用 grep/awk/sed/等。只留下 kMDItemTextContent 的值?

您可以使用 mdimport -t -d3 我的文件之一的部分输出作为示例。

    kMDItemPageHeight = 842;
    kMDItemPageWidth = 595;
    kMDItemPhysicalSize = 12288;
    kMDItemSecurityMethod = None;
    kMDItemTextContent = "11/8 - Hash Tag Test Document #HashTag1 this is the first hash tag. #HashTag2 this is the second hash tag. The following hash tag is inside and at the end of a paragraph: #HashTag3 The next hash tag #HashTag4 is in the middle of a paragraph.";
    kMDItemTitle = "11/8 - Hash Tag Test Document";
    kMDItemVersion = "1.3";
}

注意 - 我在某些文件的文本块中看到了明确的 \n\n 字符。

我想,我更具体的问题是,如何获取这两个分隔符之间的所有文本?

kMDItemTextContent = "

";

【问题讨论】:

    标签: macos awk sed grep zsh


    【解决方案1】:

    这里是简单的单行awk 脚本:

    awk -F\" '/kMDItemTextContent/{print $2}' input.txt
    

    用你的命令管道这个awk脚本:

    mdimport -t -d3 $file | awk -F\" '/kMDItemTextContent/{print $2}'
    

    【讨论】:

    • 哇。完美的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    • 2011-07-19
    • 2022-11-30
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    相关资源
    最近更新 更多