title: Concatenate values from non-adjacent objects based on multiple matching criteria
body: <p>I <a href="https://stackoverflow.com/questions/71865329/concatenate-values-from-adjacent-objects-using-jq">received help on a related question</a> previously on this forum and am wondering if there is a similarly straightforward way to resolve a more complex issue.</p>
  <p>Given the following snippet, is there a way to merge the partial sentence (the one which does not end with a &quot;[punctuation mark][white space]&quot; pattern) with its remainder based on the matching TextSize? When I tried to adjust the answer from the related question I quickly ran into issues, but I am basically looking to translate a rule such as <code>if .Text !endswith(&quot;[punctuation mark][white space]&quot;) then .Text + next .Text where .TextSize matches</code></p>
  <pre><code>  {
      &quot;Text&quot;: &quot;Was it political will that established social democratic policies in the 1930s and &quot;,
      &quot;Path&quot;: &quot;P&quot;,
      &quot;TextSize&quot;: 9
    },
    {
      &quot;Text&quot;: &quot;31 Lawrence Mishel and Jessica Schieder, Economic Policy Institute website, May 24, 2016 at (https://www.epi.org/publication/as-union-membership-has-fallen-the-top-10-percent-have-been-getting-a-larger-share-of-income/). &quot;,
      &quot;Path&quot;: &quot;Footnote&quot;,
      &quot;TextSize&quot;: 8
    },
    {
      &quot;Text&quot;: &quot;Fig. 9.2 Higher union membership has been associated with a higher share of income to lower income brackets (the lower 90%) and a lower share of income to the top 10% of earners. &quot;,
      &quot;Path&quot;: &quot;P&quot;,
      &quot;TextSize&quot;: 8
    },
    {
      &quot;Text&quot;: &quot;1940s, or that undermined them after the 1970s? Or was it abundant and cheap energy resources that enabled social democratic policies to work until the 1970s, and energy constraints that forced a restructuring of policy after the 1970s? &quot;,
      &quot;Path&quot;: &quot;P&quot;,
      &quot;TextSize&quot;: 9
    },
    {
      &quot;Text&quot;: &quot;Recall that my economic modeling discussed in Chap. 6 shows that, even with no change in the assumption related to labor \u201cbargaining power,\u201d you can explain a shift from increasing to declining income equality (higher equality expressed as a higher wage share) by a corresponding shift from a period of rapidly increasing per capita resource consumption to one of constant per capita resource consumption. &quot;,
      &quot;Path&quot;: &quot;P&quot;,
      &quot;TextSize&quot;: 9
    }
  </code></pre>
  <p>The result I'm looking for would be as follows:</p>
  <pre><code>  {
      &quot;Text&quot;: &quot;Was it political will that established social democratic policies in the 1930s and 1940s, or that undermined them after the 1970s? Or was it abundant and cheap energy resources that enabled social democratic policies to work until the 1970s, and energy constraints that forced a restructuring of policy after the 1970s? &quot;,
      &quot;Path&quot;: &quot;P&quot;,
      &quot;TextSize&quot;: 9
    },
    {
      &quot;Text&quot;: &quot;31 Lawrence Mishel and Jessica Schieder, Economic Policy Institute website, May 24, 2016 at (https://www.epi.org/publication/as-union-membership-has-fallen-the-top-10-percent-have-been-getting-a-larger-share-of-income/). &quot;,
      &quot;Path&quot;: &quot;Footnote&quot;,
      &quot;TextSize&quot;: 8
    },
    {
      &quot;Text&quot;: &quot;Fig. 9.2 Higher union membership has been associated with a higher share of income to lower income brackets (the lower 90%) and a lower share of income to the top 10% of earners. &quot;,
      &quot;Path&quot;: &quot;P&quot;,
      &quot;TextSize&quot;: 8
    },
    {
      &quot;Text&quot;: &quot;Recall that my economic modeling discussed in Chap. 6 shows that, even with no change in the assumption related to labor \u201cbargaining power,\u201d you can explain a shift from increasing to declining income equality (higher equality expressed as a higher wage share) by a corresponding shift from a period of rapidly increasing per capita resource consumption to one of constant per capita resource consumption. &quot;,
      &quot;Path&quot;: &quot;P&quot;,
      &quot;TextSize&quot;: 9
    }
  </code></pre>