Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

converting files from dos to unix

72 views
Skip to first unread message

Joao Coelho

unread,
Apr 15, 2002, 11:01:43 AM4/15/02
to
--0-1884588808-1018882832=:29128
Content-Type: text/plain; charset=us-ascii

I copied some files from a dos format to my linux machine. Now i have ^M at the end of the lines, and there are too many files for me to fix it manually. I also tried to use mtools and i still had a problem. Is there another way to convert dos text files to unix ?

Joao Coelho


---------------------------------
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
--0-1884588808-1018882832=:29128
Content-Type: text/html; charset=us-ascii

I copied some files from a dos format to my linux machine.&nbsp; Now i have ^M at the end of the lines, and there are too many files for me to fix it manually. I also tried to use mtools and i still had a problem.&nbsp; Is there another way to convert dos text files to unix ?<BR><BR>Joao Coelho<p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/welcome/?http://taxes.yahoo.com/">Yahoo! Tax Center</a> - online filing with TurboTax
--0-1884588808-1018882832=:29128--

_______________________________________________
Redhat-install-list mailing list
Redhat-in...@redhat.com
https://listman.redhat.com/mailman/listinfo/redhat-install-list

ka...@ourldsfamily.com

unread,
Apr 15, 2002, 11:07:19 AM4/15/02
to
I use vi * to edit all together, then do a search and replace on the ^M
character. The syntax in vi would be:

:%s/[ctrl-v][ctrl-m]//g

where the [] indicate key-presses, not actual typing. The line would read,
before you press enter:

:%s/^M//g

if you type it correctly. you type :%s/ and then type CTRL-V and then
CTRL-M (or just press enter), then type //g and it should look just like
the second example again. When you press enter, all instances of ^M will be
replaced with nothing.

--
Karl L. Pearson
Senior Consulting Systems Analyst
Senior Consulting Database Analyst
ka...@ourldsfamily.com
http://consulting.ourldsfamily.com
My Thoughts on Terrorism In America:
http://www.ourldsfamily.com/wtc.shtml

On Mon, 15 Apr 2002, Joao Coelho wrote:

I copied some files from a dos format to my linux machine. Now i have ^M at the end of the lines, and there are too many files for me to fix it manually. I also tried to use mtools and i still had a problem. Is there another way to convert dos text files to unix ?

Joao Coelho


---------------------------------
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax

_______________________________________________

Pete Peterson

unread,
Apr 15, 2002, 11:12:45 AM4/15/02
to

> From: Joao Coelho <ofi...@yahoo.com>
> Subject: converting files from dos to unix
> To: redhat-in...@redhat.com


>
> I copied some files from a dos format to my linux machine. Now i have ^M
> at the end of the lines, and there are too many files for me to fix it
> manually. I also tried to use mtools and i still had a problem. Is there
> another way to convert dos text files to unix ?
>
> Joao Coelho
>

You don't mention what OS release you're runninng. RH 7.2 has "dow2unix"
(Solaris has that too).

Emacs or vi can convert for you.

You can use "tr":
tr -d '\015' <infile >outfile
though you may want to put it into a script to simplify the renaming.

You can use perl to do the change and the rename
perl -pi -e 'tr /\r//d' FILENAME
or
perl -pi.bak -e 'tr /\r//d' FILENAME
if you want to save the original as a .bak.

--
pete peterson
Teradyne, Inc.
7 Technology Park Drive
Westford, MA 01886-0033

pete.p...@teradyne.com or pete...@genrad.com
+1-978-589-7478 (Office); +1-978-589-2088 (Closest FAX);
+1-978-589-7007 (Main Teradyne Westford FAX)

Saul Arias

unread,
Apr 15, 2002, 11:50:50 AM4/15/02
to
I assume you are not real comfortable with tr, perl, sed, emacs or vi.

Probably the easiest way to do it is install the dos2unix rpm.

I usually use dos2unix with the -k option. From the man pages:

-k --keepdate
Keep the date stamp of output file same as input file.

On Mon, 2002-04-15 at 10:00, Joao Coelho wrote:
> I copied some files from a dos format to my linux machine. Now i have ^M at the end of the lines, and there are too many files for me to fix it manually. I also tried to use mtools and i still had a problem. Is there another way to convert dos text files to unix ?

_______________________________________________

skeeter da beeter bunny

unread,
Apr 15, 2002, 1:02:18 PM4/15/02
to
Using sed, the stream editor:

sed 's!.$!!g' < infile > outfile.

This will substitute nothing on the last character of each line, therefore
removing the '^M'.

Good luck!


"Joao Coelho" <ofi...@yahoo.com> wrote in message
news:2002041515003...@web10304.mail.yahoo.com...

colleen.w

unread,
Apr 20, 2002, 4:15:08 AM4/20/02
to
Try this perl script - I had the same problem and this works very well

#! /usr/bin/perl -w

while ($file = shift(@ARGV)) {
$new = $file.".unix";
die "file does not exist\n" unless (-e $file);
open(FILE,">$new");
@file = `cat $file`;
for (@file) {
s/\r//;
print FILE $_;
}
}

The command line is <thisfilename dos.txt> the output will be dos.txt.unix
with all the carridge returns removed

Saul Arias <zh...@yahoo.com> wrote in message
news:1018885761.1...@saul.etires.com...

0 new messages