PDA

View Full Version : Convert line endings (CR/LF)


ComputerX
01-22-2002, 01:56 AM
Does anyone know a good utility to convert DOS line endings to Mac?

I've tried Linebreak Converter X and Cyclone X 1.5.1. Nether of them worked for me.

I have about a hundred megs of text files.

Thanks,

Dan

sjoshi
01-22-2002, 02:21 AM
Open the file in BBEdit with "Preferences" set to CR/LF. Then change the "Preferences" to Mac style line endings and save the file with a "Save as".

If you do not have/use BBEdit, and do not want to spend for the full version,
just download their Lite version, which is free. Even that versin can do this operation.

-- sbj

;)

soob
01-22-2002, 02:29 AM
Here's a shell script that will work for you...

#! /bin/sh

for x
do
echo "Converting $x"
tr -d '\015' < "$x" > "tmp.$x"
mv "tmp.$x" "$x"
done

use your favorite editor to create the file and then make sure to make it executable...

chmod +x dos2UNIX.sh

Now, you can process as many files as you like. The script accepts single filename(s) on the command line or you can use wildcards/regular expressions to specify the files:

./dos2UNIX.sh [ab]*.dos

this will convert all files starting with 'a' or 'b' and ending with '.dos' in the current directory (which also happens to be the directory the script is located in). It's not necessary to be in the same directory as the script of the files.

HTH, Jim

mervTormel
01-22-2002, 02:58 PM
perhaps sed will service your needs:

from the sed 1liners...

http://www.dbnet.ece.ntua.gr/~george/sed/1liners.txt


TEXT CONVERSION AND SUBSTITUTION:

# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # sed v1.5 only

ComputerX
01-22-2002, 07:01 PM
Thanks All!

I took the lazy way out and did it on the Windows side using Eluent.

http://www.eluent.com/

Dan

Allasso
07-01-2008, 03:29 PM
perhaps sed will service your needs:

from the sed 1liners...

http://www.dbnet.ece.ntua.gr/~george/sed/1liners.txt


TEXT CONVERSION AND SUBSTITUTION:

# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # sed v1.5 only

How do you put "Ctrl-V" and "Ctrl-M" into a script?

hayne
07-01-2008, 03:40 PM
The part you quoted from is telling you literally what to type:

press Ctrl-V then Ctrl-M