Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This might work for you:</p> <pre><code># create multiline test data cat &lt;&lt;\! &gt;/tmp/a &gt; this &gt; this { this needs &gt; changing to &gt; that } that &gt; that &gt; ! sed '/{/!b;:a;/}/!{$q;N;ba};h;s/[^{]*{//;s/}.*//;s/this\|that/\U&amp;/g;x;G;s/{[^}]*}\([^\n]*\)\n\(.*\)/{\2}\1/' /tmp/a this this { THIS needs changing to THAT } that that # convert multiline test data to a single line tr '\n' ' ' &lt;/tmp/a &gt;/tmp/b sed '/{/!b;:a;/}/!{$q;N;ba};h;s/[^{]*{//;s/}.*//;s/this\|that/\U&amp;/g;x;G;s/{[^}]*}\([^\n]*\)\n\(.*\)/{\2}\1/' /tmp/b this this { THIS needs changing to THAT } that that </code></pre> <p>Explanation:</p> <ul> <li>Read the data into the pattern space (PS). <code>/{/!b;:a;/}/!{$q;N;ba}</code></li> <li>Copy the data into the hold space (HS). <code>h</code></li> <li>Strip non-data from front and back of string. <code>s/[^{]*{//;s/}.*//</code></li> <li>Convert data e.g. <code>s/this\|that/\U&amp;/g</code></li> <li>Swap to HS and append converted data. <code>x;G</code></li> <li>Replace old data with converted data.<code>s/{[^}]*}\([^\n]*\)\n\(.*\)/{\2}\1/</code></li> </ul> <p>EDIT:</p> <p>A more complicated answer which I think caters for more than one block per line.</p> <pre><code># slurp file into pattern space (PS) :a $! { N ba } # check for presence of \v if so quit with exit value 1 /\v/q1 # replace original newlines with \v's y/\n/\v/ # append a newline to PS as a delimiter G # copy PS to hold space (HS) h # starting from right to left delete everything but blocks :b s/\(.*\)\({.*}\).*\n/\1\n\2/ tb # delete any non-block details form the start of the file s/.*\n// # PS contains only block details # do any block processing here e.g. uppercase this and that s/th\(is\|at\)/\U&amp;/g # append ps to hs H # swap to HS x # replace each original block with its processed one from right to left :c s/\(.*\){.*}\(.*\)\n\n\(.*\)\({.*}\)/\1\n\n\4\2\3/ tc # delete newlines s/\n//g # restore original newlines y/\v/\n/ # done! </code></pre> <p>N.B. This uses GNU specific options but could be tweaked to work with generic sed's.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload