Note that there are some explanatory texts on larger screens.

plurals
  1. POSED to keep text between tags over multiple lines
    text
    copied!<p>I am very new to sed and so even with looking at examples I am totally at a loss as how to go about writing the correct code for my need (<a href="https://stackoverflow.com/questions/905180/how-to-find-text-within-in-sed">this one</a> is close but it seems not for multi-line replacement.</p> <p>Here is my input.txt</p> <blockquote> <p>This is a test of splitting...</p> <p>|firstword|secondwordthirdword fourthwordfifthwordsixthword</p> <p>This is a test of splitting...</p> <p>firstword|secondword|thirdword fourthwordfifthwordsixthword</p> <p>This is a test of splitting...</p> <p>firstwordsecondword|thirdword| fourthwordfifthwordsixthword</p> <p>This is a test of splitting...</p> <p>firstwordsecondwordthirdword |fourthword|fifthwordsixthword</p> <p>This is a test of splitting...</p> <p>firstwordsecondwordthirdword fourthword|fifthword|sixthword</p> <p>This is a test of splitting...</p> <p>firstwordsecondwordthirdword fourthwordfifthword|sixthword|</p> </blockquote> <p>What I need to do is remove all text outside of the two "|" and keep the text inside of the two "|"</p> <p>And then insert a Unicode zero-width-space between each of the words (U+200B)</p> <p>Resulting in:</p> <blockquote> <p>firstwordU+200BsecondwordU+200BthirdwordU+200BfourthwordU+200BfifthwordU+200Bsixthword</p> </blockquote> <p>I tried</p> <pre><code>sed '\|/d;/|/,$d' input.txt </code></pre> <p>UPDATE: Which doesn't do much</p> <p>And</p> <pre><code>sed -e 's/.*|\([^]]*\)|.*/\1/g' input.txt </code></pre> <p>Which comes close, but doesn't remove anything from lines that do not contain a "|" (I need to remove everything not contained inside two "|" And I don't know how to go about adding the zero-width-space between words. But like I said, I don't really know what I am doing.</p> <p>Any help would be much appreciated.</p> <p>-Nathan</p>
 

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