Strips \n (newlines/CR) from textfiles (using Perl)

Steve D. Sharples

Last update: 30th May 2002

Random link: TCP/IP Control of a LeCroy DSO with Linux
Random link: Linux on a Dell Latitude CP M233XT
Random link: Agfa Snapscan 310 with Linux
Random link: Eagle PCB -> LPKF Milling Machine Mini-How-To
Random link: Installing PCI230/PCI260 Comedi driver on a RedHat 9 system (PDF)
Random link: The steve (a new unit of measurement)

What It Does

Very simply, it strips single newlines in a text-file, and replaces them with spaces. Multiple newlines it leaves alone. "What good's that?" I hear you ask?

Well, imagine you're typing a textfile in your favourite editor. Not a script, a program, or anything technical like that, just words and stuff. So you've got "word wrap" turned on, which means that at the end of the line (wherever that may be) the text editor automatically inserts a "newline" for you.

Then, you want to load it into your word processor, and of course you find that all those newlines are still there, and you have to delete them all manually. A very tedious process. There's probably some easy way of doing it in "vi", I don't know.

What "strip_nl" does is strips single newlines, leaving double ones alone. That way, you can still tell the paragraphs apart.

Here's the file, it's written in Perl, which is standard on most (if not all) UNIX systems:

Have a look at the source, convince yourself that it does nothing sinister, download it and make use of it. (you'll have to "chmod a+x"). Usage instructions can be found by simply typing ""

Hope it's useful, I can't believe that there's not something like this out there already. Does everyone write their own or something? Or, like me, spend hours pressing "[End] [Del] [space]"?

Any comments, or even if you download it and actually use it, please mail me (remove the no.spams).

Feel free to modify, redistribute etc under the terms of the GNU Public License