Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

vi / vim

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
chrno
Posts: 8
Joined: 2006-04-23 17:37

vi / vim

#1 Post by chrno »

I've got a bunch of text files that need to be converted from Dos to Linux format i.e. the CRLR thingy ...

What I'm doing now is to open each of them in vim and manually convert them from there using this command
:set ff=unix
:wq

Is it possible to have vim run this automatically? Perhaps via a script? So I can batch the whole process?

Thanks!

anaximander
Posts: 13
Joined: 2006-04-23 13:02

#2 Post by anaximander »

There are a few ways you can do this. A sed one-liner is convenient:

Code: Select all

sed -i 's/^M//' file-to-undos
(To get the ^M character into a bash command line, type Ctrl-V Ctrl-M).

Or you could look at the tofrodos package. Bit limited, though.

If you have to recurse down through directories converting all the text files in them:

Code: Select all

find directory-to-undos -type f | xargs sed -i 's/^M//'
For more complicated requirements, like where you have to convert only certain types of files, best to write a script. I could post a small Perl script I sometimes use for that sort of thing if you need it.

Cheers!

lacek
Posts: 764
Joined: 2004-03-11 18:49
Location: Budapest, Hungary
Contact:

#3 Post by lacek »

If you have installed the sysutils package, you can do this:

Code: Select all

fromdos *
This program has its counterpart, todos, which works the opposite way.

ajdlinux
Posts: 2452
Joined: 2006-04-23 09:37
Location: Port Macquarie, NSW, Australia

#4 Post by ajdlinux »

So, the quick way if you have sysutils:

Code: Select all

find | grep ".txt" | xargs fromdos
will find all .txt files in the current directory and in all subdirectories, and run them through fromdos.

chrno
Posts: 8
Joined: 2006-04-23 17:37

#5 Post by chrno »

Many thanks everyone!

I did a

Code: Select all

apt-get install sysutils
and

Code: Select all

fromdos *


did the trick! :D

Post Reply