【发布时间】:2023-01-27 18:54:23
【问题描述】:
我有一个这种类型的 json:
{
"_index": "indexeer",
"_type": "_doc",
"_id": "3233233233",
"_score": 1,
"_source": {
"Bibtex": {
"Article": {
"AuthorList": [
{
"Affiliation": {
"Affiliation": "Title content, Hematology and Hepatology Honorary Fellow, Honorary Member, American Society. xxxyyy@hotmail.com."
}
}
]
}
}
}
}
我像这样使用jq得到Affiliation:
jq -r '._source.Bibtex.Article.AuthorList[]? | .Affiliation.Affiliation | .[0:rindex(" Electronic address:")]' results.json
它工作得很好,并为我提供了我需要的隶属关系。
但是,我现在还需要 id 字段并生成如下所示的 csv:
"3233233233", "Title content, Hematology and Hepatology Honorary Fellow, Honorary Member, American Society"
我可以像这样轻松地单独获取 ID:
jq -r '._id' results.json
但是,我如何组合这两个查询来生成一个由id 和affiliation 组成的输出?
本质上我想结合这两个查询。
【问题讨论】: