将条目视为主键,一次打印,将相关联的条目数组打印为CSV,放置为空

时间:2019-05-14 13:50:39

标签: jq

我有类似这样的记录,有时有重复的body { margin: 0; padding: 0; } .gallery-item-wrap { width: 70vw; margin: 0 auto; } figure { margin: 0; } figure img { width: 100%; height: auto; } figure.zoomed { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 99; overflow: hidden; } figure.zoomed img { transform: scale(2); } 条目,尽管有不同的$('.zoom').click(function () { $(this).toggleClass('zoomed'); }); $('.zoom') .on('mousemove', function(e){ $(this).children('.zoom img').css({'transform-origin': ((e.pageX - $(this).offset().left) / $(this).width()) * 100 + '% ' + ((e.pageY - $(this).offset().top) / $(this).height()) * 100 +'%'}); })

例如,srcPath在一条记录中出现3次,而references不同。

我想打印一次唯一的/content/dam/foo/about-bar/photos/rayDavis.PNG和相关的references

我也有空记录,

srcPath

我不想看到那些。

我真的很想使用csv:

references,也许是一个不同的字段,例如{ "pages": [] } ,以及第一个srcPath,第二个published,第三个reference等-关联的{{1 }}数组作为同一行上连续的逗号分隔值,例如:

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" ,我将不能在csv中有唯一的srcPath行?

数据:

references

1 个答案:

答案 0 :(得分:1)

您可以使用以下内容:

jq --raw-output '.pages | group_by(.srcPath)[] | [.[0].srcPath, .[0].published, .[].references[]] | @csv'

我们将页面按srcPath分组,并将每个组映射到一个数组,该数组包含srcPath和该组的第一个元素的发布以及该组的每个元素的引用。这些数组中的每个数组都将在CSV结果中排成一行。

Try it here !

相关问题