[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
Here is my version of converting between types. It is built for the
most part on a shell program posted by: Evan Ron Aussenberg
many months ago.
My version of Mr. Aussenberg's progran is for ksh users and uses the
alias function of ksh rather than the ln command Mr. Aussenberg used
i.e., he used the name of the program to decide what function was being
called. I use the name of the function. This has the advantage of not
having a surfit of files in your ~/bin that do the same thing and are
really clones of one-another via the ln command.
I don't say my version is better, just different. (Memory says that the
MS-DOS to Unix option doesn't work. Since I don't have an MS-DOS
machine, I could care less.)
Joe Walters att!ihlpm!bird NW 31K14 (708) 224-7189
To know, and not to do, is not yet to know.
================================================================
The following goes in your .kshrc or equivalent
# Convert ASCII files between formats:
#Unix to Apple
function utoa { . ~bird/bin/utoa $* ; }
#Apple to Unix
function atou { . ~bird/bin/utoa $* ; }
#MS DOS to Unix
function mtou { . ~bird/bin/utoa $* ; }
#Unix to MS DOS
function utom { . ~bird/bin/utoa $* ; }
================================================================
The following is the shell script that goes in your ~/bin. The leading
colon is from Mr. Aussenberg and is to provide "portability" between
shells. Since this implementation is for ksh the colon isn't needed,
however it is provided for those without access to ksh.
:
#####################################################################
# atou / utoa / mtou (AppleToUnix or UnixToApple MsdosToUnix)
# December 15, 1990 - Evan Ron Aussenberg
# erast1@unix.cis.pitt.edu
# IN%"erast1@pittunix"
#
# Discription:
# An Apple-to-Unix, Unix-to-Apple, MSDOS-to-Unix text file
# converter. This is a Unix shell script. If you don't use Unix
# then you don't need this (Well... maybe you do, but you can't use it).
#
# Disclaimer:
# You're mileage may differ. Also, this is just a little
# nicer than making a t/csh alias... and it'll run from any shell
# as long as you leave the ':' in the 1st line. Okay? Okay.
#
# To run this shell script you need :
# 1: The unix command "basename" | Just make sure these programs can
# 2: The unix command "tr" | be found in your $PATH environ.
# 3: Save this program as "utoa"
# 4: Type "chmod a+x utoa"
# 5: Type "ln utoa atou" | If you don't have the command
# | "ln" or "link" then use "cp"
#
# Syntax:
# atou [-v | V] file1 files2...
# utoa [-v | V] file1 files2...
# mtou [-v | V] file1 files2...
#
# Options (specifiy only one):
# -v Give terse output. Normally no output is given.
# -V Give verbose output
#
########################################################################
command=`basename $0` # What command has called us here?
verbose='0'
case $command in
utoa) oct1="'\012'" # This is control-j octal
oct2="'\015'";; # This is control-m octal
atou) oct1="'\015'" # This is control-m octal
oct2="'\012'";; # This is control-j octal
mtou) oct1="'\015'" # This is control-m octal
oct2="";; # Translate it to null
utom) oct1=""
oct2="utom" ;;
esac
# Check any options. If you're file is actually named "-v or -V"
# and you're a unix neophyte... hee hee.
case $1 in
-v ) verbose=1 ; shift ;;
-V ) verbose=2 ; shift ;;
* ) ;;
esac
# Check to make sure some files were specified
if [ $# -gt 0 ]
then
for file in $* ; do
if [ -f $file ]
then
[ $verbose = 1 ] && echo -n $command': '$file'... '
[ $verbose = 2 ] && echo -n $command': Saving '$file' to '$command.$$'... '
if [ "$oct2" = "" ]
then
cat $file | tr -d "$oct1" > $command.$$
[ $verbose -gt 0 ] && echo "done $command."
[ $verbose = 2 ] && echo $command': Moving '$command.$$' to '$file
mv $command.$$ $file
[ $verbose = 2 ] && echo
continue
if [ "$oct2" = "utom" ]
then
xawk '
BEGIN {
outfile = ARGV[1]
ARGV[1] = ""
}
{
x = $0 "\r"
print x >> outfile
}' command.$$ $file
[ $verbose -gt 0 ] && echo "done $command."
[ $verbose = 2 ] && echo $command': Moving '$command.$$' to '$file
mv $command.$$ $file
[ $verbose = 2 ] && echo
continue
fi
fi
echo "do vanilla. x${oct1}x x${oct2}x" > try
cat $file | tr $oct1 $oct2 > $command.$$
[ $verbose -gt 0 ] && echo "done vanilla $command."
[ $verbose = 2 ] && echo $command': Moving '$command.$$' to '$file
mv $command.$$ $file
[ $verbose = 2 ] && echo
else
if [ -d $file ]
then
echo "${command}: $file is a directory - skipping"
else
echo "${command}: Can't find $file... Skipping"
fi
fi
done
else
echo -n '
'$command': No file names specified!
Syntax:
atou [-v | V] file1 files2...
utoa [-v | V] file1 files2...
'
fi
echo
--
Joe Walters att!ihlpm!bird, NW 31-K14 (708) 224-7189
To know, and not to do, is not yet to know