[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: LF --> CR on a UNIX?? HELP!
In article <bazyar.729761539@teal> bazyar@teal.csn.org (Jawaid Bazyar) writes:
>kenh@pacifier.rain.com (Ken Hoffmann) writes:
>
> [Ramblings Deleted]
>
> This script only works on one file at a time because it's also a
>shell-independent script. I could write one for csh that would do
>multiple files, but I don't know /bin/sh. Anyone?
>
>--
> Jawaid Bazyar | Ask me about the GNO Multitasking Environment
> Procyon, Inc. | for the Apple IIgs!
> bazyar@cs.uiuc.edu | P.O Box 620334
> --Apple II Forever!-- | Littleton, CO 80162-0334 (303) 933-4649
Try this one out..:) It works converting LF's to CR's and CR's to LF's...
--- Cut here and save as 'utoa' ---
###########################################################################
# atou / utoa (AppleToUnix & UnixToApple)
# December 15, 1990 - Evan Ron Aussenberg
# erast1@unix.cis.pitt.edu
# IN%"erast1@pittunix"
#
# Discription:
# An Apple-to-Unix and Unix-to-Apple 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...
#
# 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
*) echo "Hey, please name this program utoa and/or atou"
exit 1;
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.$$'... '
cat $file | tr $oct1 $oct2 > $command.$$
[ $verbose -gt 0 ] && echo 'done.'
[ $verbose = 2 ] && echo $command': Moving '$command.$$' to '$file
mv $command.$$ $file
[ $verbose = 2 ] && echo
else
echo $command": Can't find file "$file"... skipping"
fi
done
else
echo -n '
'$command': No file names specified!
Syntax:
atou [-v | V] file1 files2...
utoa [-v | V] file1 files2...
'
exit 1
fi
echo
exit 0