【发布时间】:2019-05-14 13:50:38
【问题描述】:
我有这样的记录,其中有时会出现重复的 srcPath 条目,尽管 references 不同。
例如/content/dam/foo/about-bar/photos/rayDavis.PNG在一条记录中出现3次,不同的references。
我希望将唯一的srcPath 打印一次,以及关联的references。
我也有空记录,
{
"pages": []
}
我不想看到那些。
我真的很想要一个带有以下内容的 csv:
srcPath,可能是一个不同的字段,如published,第一个reference,第二个reference,第三个reference,等等——关联references数组作为同一行上的连续逗号分隔值,比如:
"/content/dam/foo/about-bar/pdf/theplan.pdf", true, "/content/foo/en/about-bar/the-plan-and-vision/jcr:content/content2/image/link", "/content/foo/en/about-bar/the-plan-and-vision/jcr:content/content2/textboximg/boxFtr", "/content/foo/en/about-bar/the-plan-and-vision/jcr:content/content1/textboximg/text"
"/content/dam/foo/about-bar/photos/rayDavis.PNG", true, "/content/foo/en/about-bar/jcr:content/content1B/promos_1/image/fileReference", "/content/foo/en/about-bar/monkey-development/tales-of-giving/ray-moose-davis/jcr:content/content1/textboximg/fileReference", "/content/foo/en/about-bar/monkey-development/tales-of-giving/jcr:content/content1/textboximg_2/fileReference"
"/content/dam/foo/about-bar/pdf/foo_19thNewsletter.pdf", true, "/content/foo/en/gremlins/stay-tuned/jcr:content/content3/textboximg/text"
"/content/dam/foo/about-bar/pdf/barNews_fall1617.pdf", true, "/content/foo/en/gremlins/jcr:content/content2C/textboximg_114671747/text", "/content/dam/foo/about-bar/pdf/barNews_fall1617.pdf", "/content/foo/en/gremlins/stay-tuned/jcr:content/content3/textboximg_0/text"
换句话说,具有关联references 的唯一srcPath 条目。
我想如果我也想要 path,我将无法在 csv 中拥有唯一的 srcPath 行?
数据:
{
"pages": [
{
"srcPath": "/content/dam/foo/about-bar/pdf/theplan.pdf",
"srcTitle": "theplan.pdf",
"path": "/content/foo/en/about-bar/the-plan-and-vision",
"title": "the Plan and Vision",
"references": [
"/content/foo/en/about-bar/the-plan-and-vision/jcr:content/content2/image/link",
"/content/foo/en/about-bar/the-plan-and-vision/jcr:content/content2/textboximg/boxFtr",
"/content/foo/en/about-bar/the-plan-and-vision/jcr:content/content1/textboximg/text"
],
"published": false,
"isPage": "true"
}
]
}
{
"pages": []
}
{
"pages": []
}
{
"pages": [
{
"srcPath": "/content/dam/foo/about-bar/photos/rayDavis.PNG",
"srcTitle": "rayDavis.PNG",
"path": "/content/foo/en/about-bar",
"title": "About bar",
"references": [
"/content/foo/en/about-bar/jcr:content/content1B/promos_1/image/fileReference"
],
"published": true,
"isPage": "true"
},
{
"srcPath": "/content/dam/foo/about-bar/photos/rayDavis.PNG",
"srcTitle": "rayDavis.PNG",
"path": "/content/foo/en/about-bar/monkey-development/tales-of-giving/ray-moose-davis",
"title": "ray moose Davis",
"references": [
"/content/foo/en/about-bar/monkey-development/tales-of-giving/ray-moose-davis/jcr:content/content1/textboximg/fileReference"
],
"published": true,
"isPage": "true"
},
{
"srcPath": "/content/dam/foo/about-bar/photos/rayDavis.PNG",
"srcTitle": "rayDavis.PNG",
"path": "/content/foo/en/about-bar/monkey-development/tales-of-giving",
"title": "tales of Giving",
"references": [
"/content/foo/en/about-bar/monkey-development/tales-of-giving/jcr:content/content1/textboximg_2/fileReference"
],
"published": true,
"isPage": "true"
}
]
}
{
"pages": [
{
"srcPath": "/content/dam/foo/about-bar/pdf/foo_19thNewsletter.pdf",
"srcTitle": "foo_19thNewsletter.pdf",
"path": "/content/foo/en/gremlins/stay-tuned",
"title": "Stay tuned",
"references": [
"/content/foo/en/gremlins/stay-tuned/jcr:content/content3/textboximg/text"
],
"published": true,
"isPage": "true"
}
]
}
{
"pages": [
{
"srcPath": "/content/dam/foo/about-bar/pdf/barNews_fall1617.pdf",
"srcTitle": "barNews_fall1617.pdf",
"path": "/content/foo/en/gremlins",
"title": "gremlins",
"references": [
"/content/foo/en/gremlins/jcr:content/content2C/textboximg_114671747/text"
],
"published": true,
"isPage": "true"
},
{
"srcPath": "/content/dam/foo/about-bar/pdf/barNews_fall1617.pdf",
"srcTitle": "barNews_fall1617.pdf",
"path": "/content/foo/en/gremlins/stay-tuned",
"title": "Stay tuned",
"references": [
"/content/foo/en/gremlins/stay-tuned/jcr:content/content3/textboximg_0/text"
],
"published": true,
"isPage": "true"
}
]
}
【问题讨论】:
标签: jq