Newsgroups: comp.sys.apple2 Path: blue.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!cs.utexas.edu!utnut!cannon.ecf!helios.physics.utoronto.ca!neufeld From: neufeld@helios.physics.utoronto.ca (Christopher Neufeld) Subject: Re: LF to CR Conversion Message-ID: Sender: news@helios.physics.utoronto.ca (News Administrator) Organization: University of Toronto Physics/Astronomy/CITA References: <35h9pe$jc8@panix2.panix.com> <35hdq1$hp7@newsserv.cs.sunysb.edu> Date: Mon, 19 Sep 1994 15:31:33 GMT Lines: 37 In article <35hdq1$hp7@newsserv.cs.sunysb.edu>, Jason Simmons wrote: >In article <35h9pe$jc8@panix2.panix.com> moxie@panix.com (Mark Mentovai) writes: >>I want to know of a program for Unix that will change all Linefeeds >>to Carriage Returns in a specified file, > >tr can do this. Pipe your file through "tr '\015' '\012'". > Ummmmm. And when you're wondering why that didn't work, try: tr '\012' '\015' Sorry Jason! BTW, here's the script I use for this purpose: --- CUT HERE --- #! /bin/sh # # A script to convert line feeds (chr$ 0x0A) to carriage returns (0x0D) # in each file named on the invocation line. # # Usage: lf2cr ... # scratch=tempfile$$ for i do tr '\012' '\015' < $i > $scratch mv $scratch $i done --- CUT HERE --- -- Christopher Neufeld....Just a graduate student neufeld@physics.utoronto.ca "Don't edit reality for | "Genius may have its limitations, but stupidity the sake of simplicity" | is not thus handicapped." -- Elbert Hubbard Path: blue.weeg.uiowa.edu!news.uiowa.edu!uunet!panix!not-for-mail From: moxie@panix.com (Mark Mentovai) Newsgroups: comp.sys.apple2 Subject: Re: LF to CR Conversion Date: 19 Sep 1994 15:04:59 -0400 Organization: PANIX Public Access Internet and Unix, NYC Lines: 201 Message-ID: <35kncr$kbj@panix2.panix.com> References: <35h9pe$jc8@panix2.panix.com> NNTP-Posting-Host: panix2.panix.com X-Newsreader: TIN [version 1.2 PL2] It's me again (Moxie, the guy who started this thread.) I decided that since Ron Higgins submitted the 'best' LF/CR fixer (it's a script that converts MS-DOS, Apple, and Unix text files to a text file that is usable on an MS-DOS, Apple, or Unix machine. Thanks, Ron! From rhiggins@carroll1.cc.edu Date: Sun, 18 Sep 1994 09:23:24 -0500 From: Ron Higgins To: moxie@panix.com Newsgroups: comp.sys.apple2 Subject: Re: LF to CR Conversion In article <35h9pe$jc8@panix2.panix.com> you write: >OK.....I think Nulib should be able to do this, but I can't figure out >how. I want to know of a program for Unix that will change all Linefeeds >to Carriage Returns in a specified file, so I can compress it before >downloading it and having to worry about deleting pound-signs in >AppleWorks, which is a pain in the neck on large files, and the small >ones are starting to bug me now too. <-- Long Sentence! This is what I use: ---------------------------cut here-------------------------- #!/bin/sh ######################################################################## # atou (convert apple to unix) # Version: 1.0.1 # Copyright (C) 1993 by Sean Dockery. # # History: # 93.12.04: Correction of mtou and mtoa conversion bug. # 93.11.22: Inception of the script. # # Description: # This script will convert the following files when invoked with a given # command name: # # atou: Apple newlines to UNIX newlines # utoa: UNIX newlines to Apple newlines # atom: Apple newlines to MS-DOS newlines # mtoa: MS-DOS newlines to Apple newlines # utom: UNIX newlines to MS-DOS newlines # mtou: MS-DOS newlines to UNIX newlines # maketext: binary characters to text characters # # Installation: # You require the following commands to be present on your UNIX # system to use this script: # -basename # -find # -mv # -sh # -tr # # Install this script in your own $HOME/bin directory--make sure that # $HOME/bin is part of your $PATH variable (preferably located early # in the $PATH priority,) under the name 'atou'. Create soft links # to this script by using the 'ln' command. # # Example: # $ ln -s atou utoa # # Do this for all of the above named commands (utoa, atom, etc ...) # If your UNIX system does not have a link command, use 'cp' instead. # # Syntax: # $ atou [-v] [-c] # or # $ cat foo | atou [-v] - # # Primary Options: # -v: Give terse diagnostic output. # default: Normally no diagnostic output is given. # # Secondary Options: # -: Input will be taken from stdin and output directed to stdout. # No files may be declared when this option is used. # -c: Input will be taken from files and output directed to stdout. # Files must also be declared with this option. # # Bugs and Limitations: # This script will reset the file permissions of the file(s) that it # acts upon to the user's umask value. # # This script also has no way to know if a file that it is dealing with # is binary in nature; such files will always be corrupted as a result. # ######################################################################## # Determine the base command name. command=`basename $0` # Determine (based on the command name) which type of conversion that # we will be undertaking. case $command in atou) # Apple to UNIX oct1='\015' oct2='\012' ;; utoa) # UNIX to Apple oct1='\012' oct2='\015' ;; atom) # Apple to MS-DOS oct1='\015' oct2='\015\012' ;; mtoa) # MS-DOS to Apple oct1='\015\012' oct2=' \015' ;; utom) # UNIX to MS-DOS oct1='\012' oct2='\015\012' ;; mtou) # MS-DOS to UNIX oct1='\015\012' oct2=' \012' ;; maketext) # binary to text oct1='[\201-\377]' oct2='[\001-\177]' ;; *) # unknown echo "$command: unknown function \"$command\"" exit 1 ;; esac # Determine if we are to be quiet or loud. verbose=0 case $1 in -v) # verbose mode verbose=1 shift ;; esac # Determine if we are in stdin, stdout, or file mode. if ( [ $# -ne 0 ] && [ $1 = '-c' ] ) then stdin=0 stdout=1 shift elif ( [ $# -ne 0 ] && [ $1 = '-' ] ) then stdin=1 stdout=1 shift else stdin=0 stdout=0 fi # Make sure we have the correct number of arguements for the mode we are in. if ( [ $stdin -eq 1 ] && [ $# -gt 0 ] ) || ( [ $stdin -eq 0 ] && [ $# -eq 0 ] ) then echo "usage: $command [-v] [-c] , or cat | $command [-v] -" exit 1 fi if [ $stdin -eq 0 ] then for file in $* do if [ `find . -name $file -print` ] then if [ -f $file ] then if [ $stdout -eq 0 ] then mv $file "$command_$$" [ $verbose -eq 1 ] && echo -n "$command: $file..." tr "$oct1" "$oct2" < "$command_$$" > $file rm "$command_$$" [ $verbose -eq 1 ] && echo "done." else tr "$oct1" "$oct2" < $file fi else [ $verbose -eq 1 ] && echo "$command: $file is a directory." fi else [ $verbose -eq 1 ] && echo "$command: $file does not exist." fi done else tr "$oct1" "$oct2" fi -------------------------------cut here----------------------- -- Ron |_ Lightning Systems | Lightning Systems rhiggins@carroll1.cc.edu |_ (414) 363-4282 200megs | P. O. Box 4 Apple // & Van Halen Forever! | 21.6k USR Dual Standard | Mukwonago, WI 53149 ** Ask me about the new Turbo ASB for your Apple // Computer ** -- For my cooler signature: finger moxie@panix.com Mark Mentovai - MOXMAN - moxie@panix.com Newsgroups: comp.sys.apple2 Path: blue.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!yeshua.marcam.com!charnel.ecst.csuchico.edu!csusac!csus.edu!netcom.com!mnementh From: mnementh@netcom.com (David R. Villegas) Subject: Re: LF to CR Conversion Message-ID: Organization: Ministry of Love - Room 101 References: <35h9pe$jc8@panix2.panix.com> Date: Mon, 19 Sep 1994 20:48:49 GMT Lines: 30 moxie@panix.com (Mark Mentovai) wrote: >OK.....I think Nulib should be able to do this, but I can't figure out >how. I want to know of a program for Unix that will change all Linefeeds >to Carriage Returns in a specified file, so I can compress it before >downloading it and having to worry about deleting pound-signs in >AppleWorks, which is a pain in the neck on large files, and the small >ones are starting to bug me now too. <-- Long Sentence! I just use the following script (which I call jtom): #!/usr/bin/sh pid=$$ trap "rm /tmp/jtom.$pid 2> /dev/null ; mv /tmp/jtom.$pid.2 $1 2> /dev/null; \ exit" 15 2 1 while test $# -gt 0 do /usr/bin/echo -n $1 /usr/bin/echo -n ' ... ' cp $1 /tmp/jtom.$pid.2 cat $1 | tr \\012 \\015 > /tmp/jtom.$pid mv /tmp/jtom.$pid $1 rm /tmp/jtom.$pid.2 shift /usr/bin/echo 'done' done To convert ^M's to ^J's, just switch the \\012 and \\015.