Convert Windows/DOS line breaks to Unix/Linux

Posted in linux by mtjhax on October 23, 2009

Here’s a quick tip for converting a text file with Windows-style line breaks to Linux-style breaks.

I had a few Windows text files that needed converting so I Googled for a quick answer. The first bunch of results suggested things like downloading freeware programs or using Linux text editors to open and re-save the file. I figured there has to be a much more Unix-style, drama-free way to accomplish a trivial task such as removing a few excess ASCII 13 characters. Well here it is:

sed 's/[[:cntrl:]]$//' mywindowsfile.txt > mylinuxfile.txt

In English, replace any control character (carraige return is ASCII 13, also known as Ctrl-M) that is the last character in a line with an empty string. Technically the carraige return is the second-to-last character but the terminating linefeed is not considered part of the line itself.

Tagged with: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: