Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Old 01-22-2002, 12:56 AM   #1
ComputerX
Prospect
 
Join Date: Jan 2002
Posts: 5
Convert line endings (CR/LF)

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
ComputerX is offline   Reply With Quote
Old 01-22-2002, 01:21 AM   #2
sjoshi
Triple-A Player
 
Join Date: Jan 2002
Location: California
Posts: 113
Lightbulb Try BBEdit

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

sjoshi is offline   Reply With Quote
Old 01-22-2002, 01:29 AM   #3
soob
Prospect
 
Join Date: Jan 2002
Location: Milwaukie, OR
Posts: 48
Cool use a shell script...

Here's a shell script that will work for you...

Code:
#! /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...

Code:
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:

Code:
./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
soob is offline   Reply With Quote
Old 01-22-2002, 01:58 PM   #4
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
Lightbulb perhaps sed is your baby...

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
mervTormel is offline   Reply With Quote
Old 01-22-2002, 06:01 PM   #5
ComputerX
Prospect
 
Join Date: Jan 2002
Posts: 5
Thanks

Thanks All!

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

http://www.eluent.com/

Dan
ComputerX is offline   Reply With Quote
Old 07-01-2008, 02:29 PM   #6
Allasso
Triple-A Player
 
Join Date: Jan 2007
Posts: 82
Quote:
Originally Posted by mervTormel
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?
Allasso is offline   Reply With Quote
Old 07-01-2008, 02:40 PM   #7
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,459
The part you quoted from is telling you literally what to type:
Quote:
press Ctrl-V then Ctrl-M

__________________
hayne.net/macosx.html
hayne is online now   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:30 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.