chebe: (Default)
chebe ([personal profile] chebe) wrote in [community profile] command_liners2011-04-28 07:47 pm
Entry tags:

Removing Windows carriage-returns from text files

Hey all, don't think I've seen this here before, and I know there are many ways of doing this, so I thought, in a fit of geekery, that it might be fun to try and collect them all! Afterall everyone does have their own favourite programs.

I posted this at my own journal when I first came across it, but here's a new one as well;

sed -i 's/\r//' $file_name

perl -pi -e 's/\r\n/\n/g' $file_name
rpdom: Me wearing my first pair of reading glasses (Default)

[personal profile] rpdom 2011-04-28 07:17 pm (UTC)(link)
Also, if you don't mind having to write the output to another file

tr -d'\r' <$file_name1 >$file_name2


I like your methods too :)

Line-Feeds

[personal profile] babysprite 2011-04-28 07:18 pm (UTC)(link)

Thank you for these.

I'll add them to my scripts collection.

Whenever possible, I convert word-processed documents and save text as "US-ASCII" with the Dell Workstation in my office and my PowerBook at home.

My favorite text-editor is vim, for which I use "!fmt" to format text within the document. That usually removes the Windows CR/LF.

Thanks, again.

Robert
pixel: Age of the geek, baby. (Leverage) (leverage: quoteageofthegeek)

Re: Line-Feeds

[personal profile] pixel 2011-04-28 08:27 pm (UTC)(link)
Thanks for the vim tip, will have to remember that.
sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)

[personal profile] sophie 2011-04-28 08:48 pm (UTC)(link)
I normally have the programs dos2unix and unix2dos installed for this; they're pretty commonly found. It is, of course, a simple task to do yourself, but still :D

!fmt

[personal profile] babysprite 2011-04-28 11:18 pm (UTC)(link)

No problem! =)

I like to share what I know with others in the spirit of the g33k community.

I "discovered" !fmt during my first gig in tech, formatting text documents for a teletype printer.

An editor/programmer can use !fmt from the command mode in vim and add a navigational keystroke like *w* *$* *^* *[[* and *]]* depending on much of the text you want to format.

From the command-line, the programmer/editor can use fmt [option][old filename] > [new filename].

dos2unix and unix2dos

[personal profile] babysprite 2011-04-28 11:24 pm (UTC)(link)

Both have been ported to the system I'm currently logged into and these go a long way to eliminate a lot of repetitive tasks within a file or document.

A editor/programmer can also use !fmt from within the vi or vim text editor along with navigation keystrokes, depending upon the amount of text that needs to be formatted.

From the ba$h shell, one can use fmt [option][old filename] > [new filename].

jld: “0wned!!!” (0wned)

[personal profile] jld 2011-04-29 05:41 am (UTC)(link)
My .exrc has this:

" remove CRs
map *@ :%s/^V^V^M$//^M


Where the ^V and ^M are the actual literal control characters. (I'm not completely sure there aren't nviisms hiding in that, so beware.) I wrote it for the specific purpose of editing cddb files in abcde.
doldonius: (Default)

[personal profile] doldonius 2011-04-29 12:30 pm (UTC)(link)
Also, there are fromdos & todos if these two aren't available in some distro.