Stripping Carriage Returns

Bill Campbell bill at celestial.com
Thu Apr 1 10:31:02 PST 2004


On Thu, Apr 01, 2004, Bill Vermillion wrote:
>On Thu, Apr 01, 2004 at 09:43:00AM -0500, DataDoIt thus spoke:
>
>> I've seen it posted in the past about a small sed or awk script
>> that will strip out extra carriage returns from a file.
>
>> I'm on Linux.  Thnx.
>
>You don't need to write a thing.  Just used the unix2dos, or it's
>counterpart  dos2unix  that is shipped with all most all open
>source Unix like systems.

Actually there's another one that describes the process better in
my book, ``dtox''.

A perl one liner that would strip all trailing whitespace off lines might
be (trailing whitespace can cause some interesting and hard to find bugs
:-).

	perl -pe 's/\s+$/\n/'

Or if you want to edit a bunch of files in place, and keep copies:

	perl -i~ -pe 's/\s+$/\n/' file [file1 ...]

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

It is necessary for the welfare of society that genius should be
privileged to utter sedition, to blaspheme, to outrage good taste, to
corrupt the youthful mind, and generally to scandalize one's uncles.
                -- George Bernard Shaw


More information about the Filepro-list mailing list