title: Removing ids from Postman Collection with bash script - sed and regex
body: <p>I'm trying to solve an issue with Postman Collections.
  Test scripts added to collection generates additional field &quot;id&quot;.
  Id field change after each export of the Collection to file.
  Due to this fact PRs with changes in Postman Collections are very hard to read.
  I want to solve that issue with git pre commit hook and bash script which will remove all id's from script object of collection.</p>
  <p>There are three possible locations of the id in scripts object:</p>
  <ol>
  <li><strong>First element of object</strong></li>
  </ol>
  <pre><code>&quot;script&quot;:{
     &quot;id&quot;: &quot;83d9076e-64c7-47fa-9b50-b7635718c925&quot;,
     &quot;exec&quot;: [
         &quot;console.log(\&quot;foo\&quot;);&quot;
     ],
     &quot;type&quot;: &quot;text/javascript&quot;
  }
  </code></pre>
  <ol start="2">
  <li><strong>Middle of object</strong></li>
  </ol>
  <pre><code>&quot;script&quot;:{
     &quot;exec&quot;: [
         &quot;console.log(\&quot;foo\&quot;);&quot;
     ],
     &quot;id&quot;: &quot;83d9076e-64c7-47fa-9b50-b7635718c925&quot;,
     &quot;type&quot;: &quot;text/javascript&quot;
  }
  </code></pre>
  <ol start="3">
  <li><strong>End of object</strong></li>
  </ol>
  <pre><code>&quot;script&quot;:{
     &quot;exec&quot;: [
         &quot;console.log(\&quot;foo\&quot;);&quot;
     ],
     &quot;type&quot;: &quot;text/javascript&quot;,
     &quot;id&quot;: &quot;83d9076e-64c7-47fa-9b50-b7635718c925&quot;
  }
  </code></pre>
  <p>From regex point of view case 1 and 2 are the same:</p>
  <pre><code>.*&quot;id&quot;: &quot;[a-f0-9-]*&quot;,
  </code></pre>
  <p>Case 3 is different and regex which handles this option is:</p>
  <pre><code>,\n.*&quot;id&quot;: &quot;[a-f0-9-]*&quot;,
  </code></pre>
  <p>As I mentioned before, I want to use this regexp in bash script:
  <em>postmanClean.sh</em></p>
  <pre><code>#!/bin/bash
  COLLECTION_FILES=$(find . -type f -name &quot;*postman_collection.json&quot;)
  for POSTMAN_COLLECTION in ${COLLECTION_FILES}
  do
    echo &quot;Harmonizing Postman $POSTMAN_COLLECTION&quot;
    sed -i -e 's/.*&quot;id&quot;: &quot;[a-f0-9-]*&quot;\,//' ${POSTMAN_COLLECTION}          # Remove test/script ID
    sed -i -e 's/\,\n.*&quot;id&quot;: &quot;[a-f0-9-]*&quot;//' ${POSTMAN_COLLECTION}          # Remove test/script ID
  done
  </code></pre>
  <p>Above solution is incorrect. I tried different options, but this regexp are not working.
  How properly build this request to make them work with sed command?</p>
  <p>Collection file:
  <em>demo.postman_collection.json</em></p>
  <pre><code>{
      &quot;info&quot;: {
          &quot;_postman_id&quot;: &quot;258b2fe2-5768-47f8-9e82-70971bab6bbd&quot;,
          &quot;name&quot;: &quot;demo&quot;,
          &quot;schema&quot;: &quot;https://schema.getpostman.com/json/collection/v2.1.0/collection.json&quot;
      },
      &quot;item&quot;: [
          {
              &quot;name&quot;: &quot;One&quot;,
              &quot;item&quot;: [
                  {
                      &quot;name&quot;: &quot;Demo 1&quot;,
                      &quot;event&quot;: [
                          {
                              &quot;listen&quot;: &quot;test&quot;,
                              &quot;script&quot;: {
                                  &quot;id&quot;: &quot;83d9076e-64c7-47fa-9b50-b7635718c925&quot;,
                                  &quot;exec&quot;: [
                                      &quot;console.log(\&quot;foo\&quot;);&quot;
                                  ],
                                  &quot;type&quot;: &quot;text/javascript&quot;
                              }
                          }
                      ],
                      &quot;protocolProfileBehavior&quot;: {
                          &quot;disableBodyPruning&quot;: true
                      },
                      &quot;request&quot;: {
                          &quot;method&quot;: &quot;GET&quot;,
                          &quot;header&quot;: [],
                          &quot;body&quot;: {
                              &quot;mode&quot;: &quot;raw&quot;,
                              &quot;raw&quot;: &quot;foo&quot;
                          },
                          &quot;url&quot;: {
                              &quot;raw&quot;: &quot;https://postman-echo.com/delay/1&quot;,
                              &quot;protocol&quot;: &quot;https&quot;,
                              &quot;host&quot;: [
                                  &quot;postman-echo&quot;,
                                  &quot;com&quot;
                              ],
                              &quot;path&quot;: [
                                  &quot;delay&quot;,
                                  &quot;1&quot;
                              ]
                          }
                      },
                      &quot;response&quot;: []
                  }
              ],
              &quot;protocolProfileBehavior&quot;: {}
          },
          {
              &quot;name&quot;: &quot;Two&quot;,
              &quot;item&quot;: [
                  {
                      &quot;name&quot;: &quot;Demo 2&quot;,
                      &quot;event&quot;: [
                          {
                              &quot;listen&quot;: &quot;test&quot;,
                              &quot;script&quot;: {
                                  &quot;exec&quot;: [
                                      &quot;console.log(\&quot;bar\&quot;);&quot;
                                  ],
                                  &quot;type&quot;: &quot;text/javascript&quot;,
                                  &quot;id&quot;: &quot;facb28f7-c54d-46e2-adb2-4c929fd1edd3&quot;
                              }
                          }
                      ],
                      &quot;protocolProfileBehavior&quot;: {
                          &quot;disableBodyPruning&quot;: true
                      },
                      &quot;request&quot;: {
                          &quot;method&quot;: &quot;GET&quot;,
                          &quot;header&quot;: [],
                          &quot;body&quot;: {
                              &quot;mode&quot;: &quot;raw&quot;,
                              &quot;raw&quot;: &quot;bar&quot;
                          },
                          &quot;url&quot;: {
                              &quot;raw&quot;: &quot;https://postman-echo.com/delay/2&quot;,
                              &quot;protocol&quot;: &quot;https&quot;,
                              &quot;host&quot;: [
                                  &quot;postman-echo&quot;,
                                  &quot;com&quot;
                              ],
                              &quot;path&quot;: [
                                  &quot;delay&quot;,
                                  &quot;2&quot;
                              ]
                          }
                      },
                      &quot;response&quot;: []
                  },
                  {
                      &quot;name&quot;: &quot;Demo 3&quot;,
                      &quot;event&quot;: [
                          {
                              &quot;listen&quot;: &quot;test&quot;,
                              &quot;script&quot;: {
                                  &quot;exec&quot;: [
                                      &quot;console.log(\&quot;foobar\&quot;);&quot;
                                  ],
                                  &quot;id&quot;: &quot;facb28f7-c54d-46e2-adb2-4c929fd1edd3&quot;,
                                  &quot;type&quot;: &quot;text/javascript&quot;
                              }
                          }
                      ],
                      &quot;protocolProfileBehavior&quot;: {
                          &quot;disableBodyPruning&quot;: true
                      },
                      &quot;request&quot;: {
                          &quot;method&quot;: &quot;GET&quot;,
                          &quot;header&quot;: [],
                          &quot;body&quot;: {
                              &quot;mode&quot;: &quot;raw&quot;,
                              &quot;raw&quot;: &quot;bar&quot;
                          },
                          &quot;url&quot;: {
                              &quot;raw&quot;: &quot;https://postman-echo.com/delay/3&quot;,
                              &quot;protocol&quot;: &quot;https&quot;,
                              &quot;host&quot;: [
                                  &quot;postman-echo&quot;,
                                  &quot;com&quot;
                              ],
                              &quot;path&quot;: [
                                  &quot;delay&quot;,
                                  &quot;3&quot;
                              ]
                          }
                      },
                      &quot;response&quot;: []
                  }
              ],
              &quot;protocolProfileBehavior&quot;: {}
          }
      ],
      &quot;protocolProfileBehavior&quot;: {}
  }
  </code></pre>