[GLLUG] Replacing newlines in text file

Bernard Peek bap at shrdlu.com
Sun Aug 30 12:42:38 UTC 2015


> Hi List,
> 
> I have a text file with 'hard' newlines at the end of each 'line'
> (often
> mid-sentence,) and multiple newlines at the end of paragraphs. I
> need a simple incantation to change all occurrences of a *single*
> newline to a space, and leave the multiple newlines in place.
> Unfortunately I'm no good with regexp and my head is mushed with it
> after reading docs this morning.
> 
> Any pointers would be welcome - I've trued using a GUI text editor,
> but at over 100,000 'lines' that's causing problems...

This is a fairly common requirement when importing text files in to a
word-processor. Search and replace is the usual tool and lots of people
have written macros to do this. First replace sequential newlines with a
nonsense string: I use :ZZ: because that's what my first sysadmin used.
Then replace all remaining newlines with a space. Lastly replace the
nonsense string with a newline. Job done.





More information about the GLLUG mailing list