<div dir="ltr">Another option is perl ...<div><br></div><div>perl -pi -e 's/(.)\n$/$1/ ; s/\n/\n\n/' /tmp/test<br></div><div><br></div><div>The first regex will remove any single newlines that are not at the start of the line and the second will double any remaining ones.</div><div><br></div><div>If you want to see the output before writing to the file, remove the i.</div><div><br></div><div>Tom</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 30 August 2015 at 10:55, Andy Smith <span dir="ltr"><<a href="mailto:andy@bitfolk.com" target="_blank">andy@bitfolk.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Dylan,<br>
<span class=""><br>
On Sun, Aug 30, 2015 at 10:37:54AM +0100, Dylan wrote:<br>
> I have a text file with 'hard' newlines at the end of each 'line'<br>
> (often mid-sentence,) and multiple newlines at the end of paragraphs.<br>
> I need a simple incantation to change all occurrences of a *single*<br>
> newline to a space, and leave the multiple newlines in place.<br>
<br>
</span>You probably want something based on sed, e.g. from<br>
<a href="http://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed</a><br>
<br>
    sed ':a;N;$!ba;s/\n/ /' source.txt > dest.txt<br>
<br>
If you just wanted to replace every single newline with a space than<br>
tr would be much simpler:<br>
<br>
    tr '\n' ' '<br>
<br>
But that doesn't appear to be what you asked for (you asked for only<br>
the first newline).<br>
<br>
The invocation of sed is more complicated because sed is<br>
line-oriented.<br>
<br>
Cheers,<br>
Andy<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
<a href="http://bitfolk.com/" rel="noreferrer" target="_blank">http://bitfolk.com/</a> -- No-nonsense VPS hosting<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
GLLUG mailing list<br>
<a href="mailto:GLLUG@mailman.lug.org.uk">GLLUG@mailman.lug.org.uk</a><br>
<a href="https://mailman.lug.org.uk/mailman/listinfo/gllug" rel="noreferrer" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/gllug</a><br>
</div></div></blockquote></div><br></div>