Unix/NT file conversion problems
Dave Lawson
DAVELA at menasco.com
Mon Nov 30 15:37:35 GMT 1998
> We are having some problems - the majority of our files require ascii
> transfers between our unix servers and PCs. They are however being
> transferred as binary for some reason even though they are just plain
> text files. This means (when going from unix to pc) the files come down
> without a carriage return at the end of lines. And when going from pc to
> unix they end up with ^M on the end of each line. Anyone have any
> ideas?
Here are 2 shell scripts that come with IRIX. to_dos works fine on
both IRIX and AIX. I haven't tried to_unix yet.
to_dos:
#! /bin/sh -e
# convert a UNIX ASCII file to a DOS ASCII file by appending ^M at
the
# end of each line and ^Z at the end of the file
TMPFILE=/tmp/to_dos$$
if [ $# -gt 2 ]
then
echo "usage: to_dos [<unix_file> [<dos_file>]]"
exit 1
fi
if [ $# -gt 0 ]
then
nawk '{printf("%s\r\n", $0);}' "$1" > $TMPFILE
else
nawk '{printf("%s\r\n", $0);}' > $TMPFILE
fi
# Stick on the EOF character
echo '^Z\c' >> $TMPFILE
if [ $# -eq 2 ]
then
mv -f $TMPFILE "$2"
else
cat $TMPFILE
rm $TMPFILE
fi
to_unix:
#! /bin/sh -e
# convert a DOS ASCII file to a UNIX ASCII file by removing trailing
^M at the
# end of each line and ^Z at the end of the file
TMPFILE=/tmp/to_unix$$
if [ $# -gt 2 ]
then
echo "usage: to_unix [<dos_file> [<unix_file>]]"
exit 1
fi
# First strip out all carriage-return and ctrl-Z's
if [ $# -gt 0 ]
then
tr -d '\015\032' < "$1" > $TMPFILE
else
tr -d '\015\032' > $TMPFILE
fi
if [ $# -eq 2 ]
then
mv -f $TMPFILE "$2"
else
cat $TMPFILE
rm $TMPFILE
fi
Regards,
Dave Lawson
CAD Coordinator
Menasco Aerospace
Oakville, Ontario
(905) - 827-7777 ext. 398
More information about the samba
mailing list