Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jq 将条目视为主键打印一次,将关联的条目数组打印为CSV,下拉清空_Jq - Fatal编程技术网

Jq 将条目视为主键打印一次,将关联的条目数组打印为CSV,下拉清空

Jq 将条目视为主键打印一次,将关联的条目数组打印为CSV,下拉清空,jq,Jq,我有这样的记录,有时有重复的srcPath条目,尽管有不同的引用 例如,/content/dam/foo/about bar/photos/rayDavis.PNG在一条记录中出现3次,引用不同的 我想打印一次唯一的srcPath,以及相关的引用 我也有空的记录 { "pages": [] } 我不想看到那些 我非常想要一个带有以下内容的csv: srcPath,可能是一个不同的字段,如published,第一个reference,第二个reference,第三个reference,等等—

我有这样的记录,有时有重复的
srcPath
条目,尽管有不同的
引用

例如,
/content/dam/foo/about bar/photos/rayDavis.PNG
在一条记录中出现3次,引用不同的

我想打印一次唯一的
srcPath
,以及相关的
引用

我也有空的记录

{
  "pages": []
}
我不想看到那些

我非常想要一个带有以下内容的csv:

srcPath
,可能是一个不同的字段,如
published
,第一个
reference
,第二个
reference
,第三个
reference
,等等——关联的
引用数组作为同一行上的连续逗号分隔值,如:

"/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"
换句话说,具有关联的
引用的唯一
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 --raw-output '.pages | group_by(.srcPath)[] | [.[0].srcPath, .[0].published, .[].references[]] | @csv'
我们按srcPath对页面进行分组,并将每个组映射到一个数组中,该数组包含组的第一个元素的srcPath和published以及组的每个元素的引用。这些数组中的每一个都将是CSV结果中的一行


天哪,这似乎管用!!谢谢你,亚伦:)