[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to convert LF's to CR's in UNIX?



In article <CCG2zn.JyC@pacifier.rain.com> kenh@pacifier.rain.com (Ken
Hoffmann) writes:

| 	Hello net brethren, I remeber seeing a c-shell script that would
| take a UNIX text file and convert it to a Apple readable format, anyone
| know where that went?  And if someone has it, please mail it to me.

There were a few problems that popped up with the previous posting (as
I was doing it from memory), but I didn't bother to make any more
corrections as people didn't seem to be complaining to me about the
scripts not working.

I have elected to post it instead of mailing it because the old csh
script postings didn't work properly anyway.

Anyways, here are the proper working versions (tested and everything).

-u2aii converts UNIX LFs to Apple II CRs.
-maketext converts files to readable ASCII text
-striplf removes LFs from input files in case character streams were
  truncated to 255 characters by news readers or other utilities.

Warning: All of these will destroy binary files.
------------------------------- u2aii -------------------------------
#!/bin/csh -f

# u2aii: convert UNIX newlines to Apple II newlines.

# find the command name.
set cmd=$0:t

# if no files are given, then we can't do anything.
if ( $#argv == 0 ) then
    echo "usage: $cmd <filespec>"
    exit 1
endif

# do the conversion for each file (which is not a directory).
foreach file ($*)
    if ( -f $file ) then
        (cat $file | tr '\012' '\015') >! /tmp/xxx
        mv -f /tmp/xxx $file
    endif
end
------------------------------ maketext ------------------------------
#!/bin/csh -f

# maketext: strip bit 7 of every byte in input files.

# find the command name.
set cmd=$0:t

# if no files are given, then we can't do anything.
if ( $#argv == 0 ) then
    echo "usage: $cmd <filespec>"
    exit 1
endif

# do the conversion for each file (which is not a directory).
foreach file ($*)
    if ( -f $file ) then
        (cat $file | tr '[\201-\377]' '[\001-\177]') >! /tmp/xxx
        mv -f /tmp/xxx $file
    endif
end
------------------------------ striplf ------------------------------
#!/bin/csh -f

# striplf: concatenate lines of text which have been truncated to 255
#  characters terminated with LFs.

# find the command name.
set cmd=$0:t

# if no files are given, then we can't do anything.
if ( $#argv == 0 ) then
    echo "usage: $cmd <filespec>"
    exit 1
endif

# do the conversion for each file (which is not a directory).
foreach file ($*)
    if ( -f $file ) then
        (cat $file | tr -d '\012') >! /tmp/xxx
        mv -f /tmp/xxx $file
    endif
end
---------------------------------------------------------------------

| Thanks alot,
|  
| Ken

Your welcome.  I'm just glad somebody is going to use these.
-- 
 internet: dockery@griffin.cuc.ab.ca
      -or- sbdocker@acs.ucalgary.ca
      -or- dockery@pro-calgary.cts.com
 pro-line: dockery@pro-calgary