【发布时间】:2020-06-06 13:43:34
【问题描述】:
我正在尝试使用jq 将ffprobe 生成的JSON 输出的一些元素重新格式化为csv。我很接近(在我看来),但在细节上苦苦挣扎:
我的ffprobe output is shown in the jq 1.6 playground
我最近在 MacOS Mojave (10.14.6) 上运行 jq (jq --version => jq-1.6) 的 d/l 二进制文件
在我的 Mac 终端上,我的结果是:
$ fn_ffprobeall | jq -r '[.format.filename,.format.format_name,.format.tags.album_artist] | @csv'
"01 Jubilee.flac","flac","Bill Charlap Trio"
# where fn_ffprobeall is a function defined as:
fn_ffprobeall () { ffprobe -i "01 Jubilee.flac" -hide_banner -v quiet -print_format json -show_format -show_streams; }
但是这个jq 输出(如上所示)不是我需要的...我需要值没有 周围的引号""。根据the documentation为--raw-output / -r:
使用此选项,如果过滤器的结果是字符串,那么它将直接写入标准输出,而不是格式化为带引号的 JSON 字符串。这对于使 jq 过滤器与非基于 JSON 的系统对话很有用。
此外,使用 @tsv 而不是 @csv "does the right thing" 似乎很奇怪,因为引号将被删除。我想可以做一些额外的工作来用, 替换tab 字符,但我想知道在回到这种方法之前我是否遗漏了一些东西。
【问题讨论】:
标签: string csv jq quotes ffprobe