Note that there are some explanatory texts on larger screens.

plurals
  1. POSed - conditional branching within an address range
    primarykey
    data
    text
    <p>I needed to format a bulk entry file from some raw text data. I was able to achieve the bulk of my solution using <code>Sed</code>, which was/is preferred, but not absolutely required (I'd just like to stick to this one tool). The problem became clear when I got branch crazy trying to parse through [a much larger amount of] the following input:</p> <pre><code>---- Start Product ---- PartNumber&gt;&gt; 123457 Size04_Req&gt;&gt; 2 Size02_Req&gt;&gt; 1 PartColor&gt;&gt; Natural PartDescription&gt;&gt; Guys Tee ---- End Product ---- ---- Start Product ---- PartNumber&gt;&gt; TPIOO9205 Size05_Req&gt;&gt; 1 PartColor&gt;&gt; Natural PartDescription&gt;&gt; Black Hoodie ---- End Product ---- ###...with the objective of achieving the following output: ---- Start Product --- PartNumber&gt;&gt; 123457 Size01_Req&gt;&gt; 0 Size03_Req&gt;&gt; 0 Size05_Req&gt;&gt; 0 Size06_Req&gt;&gt; 0 Size04_Req&gt;&gt; 2 Size02_Req&gt;&gt; 1 PartColor&gt;&gt; Natural PartDescription&gt;&gt; Guys Tee ---- End Product ---- ---- Start Product ---- PartNumber&gt;&gt; TPIOO9205 Size01_Req&gt;&gt; 0 Size02_Req&gt;&gt; 0 Size03_Req&gt;&gt; 0 Size04_Req&gt;&gt; 0 Size06_Req&gt;&gt; 0 Size05_Req&gt;&gt; 1 PartColor&gt;&gt; Natural PartDescription&gt;&gt; Black Hoodie ---- End Product ---- </code></pre> <p>I do believe this is as simple as working within the address range <strong>/----\ Start\ Product\ ----/,/----\ End\ Product\ ----/</strong> and doing some elegant branch and :label work, but my inclination, obviously, is to jump on Awk or something for this logic - because I'm going nuts -- and it would be easier, perhaps, with another tool to achieve this. However, sticking to my original desire to stay with Sed, and because I like to learn me a new Sed trick any day, how might this be done? Notice that the logic is to insert <strong>SizeXX_Req>> 0</strong> for the sizes 01-06 that are not accounted for, and the order is not important, which is why I was thinking Sed could get even this last little part done semi-sanely. There will always be at least one <strong>SizeXX_Req</strong> line in between each Start/End Product section. Any Sed(i) Masters make quick work of this? Am I just geeking out from the boatload of regular expressions I've been writing lately and missing an easy fix?<br><br> Go ahead. Show me in another rando language without even explaining how (or why) you did, I'm down with that, too. Thanks in advance, peeps.</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.
 

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