Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting text file formats: CR/LF/CRLF



I know I've seen it discussed before, but I just can't find it in the
archives (search terms too general I guess) but I recall there is a
command line tool to convert text file formats, could someone tell me
what its called or the subject of the thread discussing this ussue
previously.

Right. Try this alias:
fixit = tr '\015' '\012'
formatted appropriately for your favorite shell, of course. :-)

Here are the quick-and-dirty shell scripts I use to automate the process of converting line endings for one or more files (mainly so I don't have to keep remembering the tr syntax). Install in any convenient /bin directory.

Cheers,
Tony M.


*** mac2unix ***

#!/bin/sh
# Shell script to convert files named by arguments from Mac to Unix line breaks
# Default is to place in new .utxt files; specify -f to replace originals

delete_orig=no
if [ "$1" = -f ]
then
delete_orig=yes
shift
fi

for i in $*
do
if [ -e "$i.utxt" ]
then
echo mac2unix: file $i.utxt exists, skipping
else
tr '\r' '\n' < "$i" > "$i.utxt"
if [ $delete_orig = yes ]
then
mv "$i.utxt" "$i"
fi
fi
done

*** unix2mac ***

#!/bin/sh
# Shell script to convert files named by arguments from Unix to Mac line breaks
# Default is to place in new .mtxt files; specify -f to replace originals

delete_orig=no
if [ "$1" = -f ]
then
delete_orig=yes
shift
fi

for i in $*
do
if [ -e "$i.mtxt" ]
then
echo unix2mac: file $i.mtxt exists, skipping
else
tr '\n' '\r' < "$i" > "$i.mtxt"
if [ $delete_orig = yes ]
then
mv "$i.mtxt" "$i"
fi
fi
done

*** dos2unix ***

#!/bin/sh
# Shell script to convert files named by arguments from DOS to Unix line breaks
# Default is to place in new .utxt files; specify -f to replace originals

delete_orig=no
if [ "$1" = -f ]
then
delete_orig=yes
shift
fi

for i in $*
do
if [ -e "$i.utxt" ]
then
echo dos2unix: file $i.utxt exists, skipping
else
tr -d '\r' < "$i" > "$i.utxt"
if [ $delete_orig = yes ]
then
mv "$i.utxt" "$i"
fi
fi
done
_______________________________________________
darwin-userlevel mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-userlevel
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Converting text file formats: CR/LF/CRLF (From: Dave Taylor <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.