使用 grep/awk/sed/etc 解析 mdimport 的输出。在 macOS 上?

Parse output of mdimport using grep/awk/sed/etc. on macOS?

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

mdimport -t -d3 $file 

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

如何使用grep/awk/sed/etc。只给我 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 = "

";

这是简单的单行awk脚本:

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

使用您的命令管道此 awk 脚本:

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