💾 Archived View for mirrors.apple2.org.za › archive › apple2.archive.umich.edu › apple2 › unix › lf.… captured on 2024-05-10 at 14:22:29.

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Article 61159 of comp.sys.apple2:
Newsgroups: comp.sys.apple2
Path: caen!saimiri.primate.wisc.edu!ames!agate!library.ucla.edu!news.mic.ucla.edu!unixg.ubc.ca!acs.ucalgary.ca!sbdocker
From: sbdocker@acs.ucalgary.ca (Sean Brendan Dockery)
Subject: UNIX/Apple textfile/newline problems?  Some remedies follow..
Message-ID: <Aug22.210155.29499@acs.ucalgary.ca>
Date: Sun, 22 Aug 1993 21:01:55 GMT
Organization: Griffin Software Development
Keywords: UNIX Apple newlines text convert
Lines: 185

A little while ago, Brian Tao complained about munged files on comp.-
binaries.apple2.  I tried to post this from another site, but it
apparently wasn't circulated -- it didn't show up at the university.

In article <CBpywC.9EJ@wave.scar.utoronto.ca>
90taobri@wave.scar.utoronto.ca (TAO BRIAN T) writes:

|      ARGH!!!!!  You are posting CR-terminated Binscii files!  UNIX text
| files end with LF's!  News software will see your Binscii files as one
| long line and break it up into 255-character chunks.  Same thing
| happened the second time you posted it, so _no_ you are _not_ getting
| any better at this!  Not to mention posting an outdated version (0.6) to
| begin with... Wanna know how much money you just wasted?
| 
| (ignore me, I'm in a pissy mood today...)

Well, rather than ignore you -- how about a couple of shell scripts
for the benefit of the wider audience?  I have posted C shell and Korn
shell versions for those people with various flavours of unices.

Following are three scripts:

- striplf: concatenate lines ending with UNIX newlines (LF's) caused
	by being truncated by news software.
- aii2u: convert Apple // newlines (CR's) to UNIX newlines (LF's).
- maketext: strip bit seven of every byte in a text file making it
	completely text.

They are invoked from the command line by

	<scriptname> <file(s)-to-convert>

Output files retain the same names as input files.

NOTE: All of these scripts are for use on text files only.  Because of
their nature, they will corrupt binary files (or at least make them
quite unpredictable).

----------------------- striplf (csh version) -----------------------
#!/bin/csh

# striplf (csh version): strip UNIX newlines from a file that has had
#  line lengths truncated to 255 characters.

if ( $#argv == 0 ) ; then
	echo "usage: $0:t <filespec>"
	exit 1
endif

foreach file ($*)
	(cat $file | tr -d '\012') > /tmp/xxx
	mv xxx $file
end
----------------------- striplf (ksh version) -----------------------
#!/bin/ksh

# striplf (ksh version): strip UNIX newlines from a file that has had
#  line lengths truncated to 255 characters.

if [ $# = 0 ] ; then
	echo "usage: ${0##*/} <filespec>"
	exit 1
fi

for file in $*
	cat $file | tr -d '\012' > /tmp/xxx
	mv xxx $file
done
---------------------------------------------------------------------

The second one will convert Apple // newlines (CR's) to UNIX newlines
(LF's).

------------------------ aii2u (csh version) ------------------------
#!/bin/csh

# aii2u (csh version): script to convert files with Apple // newlines
#  to files with UNIX newlines

if ( $#argv == 0 ) ; then
	echo "usage: $0:t <filespec>"
	exit 1
endif

foreach file ($*)
	(cat $file | tr '\015' '\012') > /tmp/xxx
	mv /tmp/xxx $file
end
------------------------ aii2u (ksh version) ------------------------
#!/bin/ksh

# aii2u (ksh version): script to convert files with Apple // newlines
#  to files with UNIX newlines

if [ $# = 0 ] ; then
	echo "usage: ${0##*/} <filespec>"
fi

for file in $*
	cat $file | tr '\015' '\012' > /tmp/xxx
	mv /tmp/xxx $file
done
---------------------------------------------------------------------

I also have problems with some of the files that I FTP.  Some of them
come down the line with the eighth bit of every byte set (making text
files quite unruly when trying to edit for brevity with emacs).

----------------------- maketext (csh version) ----------------------
#!/bin/csh

# maketext (csh version): strip bit seven of every byte in input
#  file(s). 

if ( $#argv == 0 ) ; then
	echo "usage: $0:t <filespec>"
	exit 1
endif

foreach file ($*)
	(cat $file | tr '[\200-\377]' '[\000-\177]') > /tmp/xxx
	mv /tmp/xxx $file
end
----------------------- maketext (ksh version) ----------------------
#!/bin/ksh

# maketext (ksh version): strip bit seven of every byte in input
#  file(s). 

if [ $# = ] ; then
	echo "usage: ${0##*/} <filespec>"
	exit 1
fi

for file in $*
	cat $file | tr '[\200-\377]' '[\000-\177]' > /tmp/xxx
	mv /tmp/xxx $file
done
---------------------------------------------------------------------

NOTE: In some cases, people have their "noclobber" variable set in
their C shell environment (or the equivalent for the Korn shell).  In
these cases, these scripts will fail.

It is necessary to make the following modifications to "force" them to
work in such conservative environments.

For C shells, change

	from			--->	to
	-----------------------		---------------------
	... > /tmp/xxx		--->	... >! /tmp/xxx
	mv /tmp/xxx $file	--->	mv -f /tmp/xxx $file

For Korn shells, change

	from			--->	to
	-----------------------		---------------------
	... > /tmp/xxx		--->	... >| /tmp/xxx
	mv /tmp/xxx $file	--->	mv -f /tmp/xxx $file

All of these scripts just need to be put in a directory in your $PATH
variable on the UNIX host.  If you haven't already set up a $HOME/bin
directory for yourself (created the directory and added $HOME/bin to
your $PATH variable), now would be a good time.

For csh, add the following to your .cshrc file:

	set path=($HOME/bin $PATH)

For ksh, add the following to your .profile file:

	export PATH=$HOME/bin:$PATH

I did not post this to comp.sources.apple2 in light of the fact that
some people who don't have access to that newsgroup, but who might be
using GNO, would be able to use these.  The csh scripts should be
completely compatible.

I hope that *someone* out there finds these scripts useful.  :)
-- 
 internet: dockery@griffin.cuc.ab.ca
      -or- sbdocker@acs.ucalgary.ca
      -or- dockery@pro-calgary.cts.com
 pro-line: dockery@pro-calgary


Article 61160 of comp.sys.apple2:
Newsgroups: comp.sys.apple2
Path: caen!destroyer!nntp.cs.ubc.ca!cs.ubc.ca!unixg.ubc.ca!acs.ucalgary.ca!sbdocker
From: sbdocker@acs.ucalgary.ca (Sean Brendan Dockery)
Subject: Re: UNIX/Apple textfile/newline problems?  Some remedies follow..
Message-ID: <Aug22.210647.29520@acs.ucalgary.ca>
Date: Sun, 22 Aug 1993 21:06:47 GMT
References: <Aug22.210155.29499@acs.ucalgary.ca>
Organization: Griffin Software Development
Keywords: UNIX Apple newlines text convert
Lines: 29

I noticed two typo's in my previous posting.

In article <Aug22.210155.29499@acs.ucalgary.ca>
sbdocker@acs.ucalgary.ca (Sean Brendan Dockery) writes:

| ----------------------- striplf (csh version) -----------------------
[ ... ]
| foreach file ($*)
| 	(cat $file | tr -d '\012') > /tmp/xxx
| 	mv xxx $file
           ^^^

Change to /tmp/xxx.

| ----------------------- striplf (ksh version) -----------------------
[...]
| for file in $*
| 	cat $file | tr -d '\012' > /tmp/xxx
| 	mv xxx $file
           ^^^

Change to /tmp/xxx.

Oops!  :)
-- 
 internet: dockery@griffin.cuc.ab.ca
      -or- sbdocker@acs.ucalgary.ca
      -or- dockery@pro-calgary.cts.com
 pro-line: dockery@pro-calgary


Article 61162 of comp.sys.apple2:
Newsgroups: comp.sys.apple2
Path: caen!saimiri.primate.wisc.edu!ames!agate!library.ucla.edu!news.mic.ucla.edu!unixg.ubc.ca!acs.ucalgary.ca!sbdocker
From: sbdocker@acs.ucalgary.ca (Sean Brendan Dockery)
Subject: Re: UNIX/Apple textfile/newline problems?  Some remedies follow..
Message-ID: <Aug22.220404.31132@acs.ucalgary.ca>
Date: Sun, 22 Aug 1993 22:04:04 GMT
References: <Aug22.210155.29499@acs.ucalgary.ca>
Organization: Griffin Software Development
Keywords: UNIX Apple newlines text convert
Lines: 98

Yet more corrections..

In article <Aug22.210155.29499@acs.ucalgary.ca>
sbdocker@acs.ucalgary.ca (Sean Brendan Dockery) writes:

| ----------------------- striplf (ksh version) -----------------------
| #!/bin/ksh
| 
| # striplf (ksh version): strip UNIX newlines from a file that has had
| #  line lengths truncated to 255 characters.
| 
| if [ $# = 0 ] ; then
| 	echo "usage: ${0##*/} <filespec>"
| 	exit 1
| fi
| 
| for file in $*
  ^^^^^^^^^^^^^^

Change to 'for file in $* ; do'

| 	cat $file | tr -d '\012' > /tmp/xxx
| 	mv xxx $file
| done

| ------------------------ aii2u (ksh version) ------------------------
| #!/bin/ksh
| 
| # aii2u (ksh version): script to convert files with Apple // newlines
| #  to files with UNIX newlines
| 
| if [ $# = 0 ] ; then
| 	echo "usage: ${0##*/} <filespec>"
| fi
| 
| for file in $*
  ^^^^^^^^^^^^^^

Change to 'for file in $* ; do'

| 	cat $file | tr '\015' '\012' > /tmp/xxx
| 	mv /tmp/xxx $file
| done

| ----------------------- maketext (csh version) ----------------------
| #!/bin/csh
| 
| # maketext (csh version): strip bit seven of every byte in input
| #  file(s). 
| 
| if ( $#argv == 0 ) ; then
| 	echo "usage: $0:t <filespec>"
| 	exit 1
| endif
| 
| foreach file ($*)
| 	(cat $file | tr '[\200-\377]' '[\000-\177]') > /tmp/xxx
                           ^^^           ^^^

Change to 201 and 001, respectively.

| 	mv /tmp/xxx $file
| end
| ----------------------- maketext (ksh version) ----------------------
| #!/bin/ksh
| 
| # maketext (ksh version): strip bit seven of every byte in input
| #  file(s). 
| 
| if [ $# = ] ; then
       ^^^^

Change to '$# = 0'

| 	echo "usage: ${0##*/} <filespec>"
| 	exit 1
| fi
| 
| for file in $*
  ^^^^^^^^^^^^^^

Change to 'for file in $* ; do'

| 	cat $file | tr '[\200-\377]' '[\000-\177]' > /tmp/xxx
                          ^^^           ^^^

Change to 201 and 001, respectively.

| 	mv /tmp/xxx $file
| done
| ---------------------------------------------------------------------

I hope that I have caught all of my mistakes this time.  Sheesh.  :)
-- 
 internet: dockery@griffin.cuc.ab.ca
      -or- sbdocker@acs.ucalgary.ca
      -or- dockery@pro-calgary.cts.com
 pro-line: dockery@pro-calgary