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!
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
-
- Posts: 13
- Joined: 2006-04-23 13:02
There are a few ways you can do this. A sed one-liner is convenient:
(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:
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!
Code: Select all
sed -i 's/^M//' file-to-undos
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//'
Cheers!
If you have installed the sysutils package, you can do this:
This program has its counterpart, todos, which works the opposite way.
Code: Select all
fromdos *
So, the quick way if you have sysutils:
will find all .txt files in the current directory and in all subdirectories, and run them through fromdos.
Code: Select all
find | grep ".txt" | xargs fromdos
Many thanks everyone!
I did a and
did the trick!
I did a
Code: Select all
apt-get install sysutils
Code: Select all
fromdos *
did the trick!