home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1968 < prev    next >
Text File  |  1990-12-28  |  2KB  |  64 lines

  1. Newsgroups: alt.sources
  2. From: michaelp@dadla.WR.TEK.COM (Michael Prusynski)
  3. Subject: [comp.unix.shell] file conversion (was Re: How to strip edit characters)
  4. Message-ID: <1990Oct18.173851.17764@math.lsa.umich.edu>
  5. Date: Thu, 18 Oct 90 17:38:51 GMT
  6.  
  7. Archive-name: cnvt/17-Oct-90
  8. Original-posting-by: michaelp@dadla.WR.TEK.COM (Michael Prusynski)
  9. Original-subject: file conversion (was Re: How to strip edit characters)
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.unix.shell.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15.  
  16. With the recent discussion on stripping ^H and ^M etc. from files,
  17. I thought I'd contribute my general purpose "cnvt" shell script.
  18. Bill Pfiefer was the originator of this program, but I've modified it
  19. and added to it quite a bit.  The "delbs" function is for nroff output,
  20. and also deletes the underscore or bold character.  b2ul is not guaranteed.
  21. The type of conversion you want must be the first argument.
  22. ---------- cut here -----------
  23. : cnvt - Michael Prusynski - July,1987
  24. PATH=/bin:$PATH
  25. usage="usage: cnvt {addcr,delbs,delcr,delff,b2u,cr2lf,lf2cr,indent,sp2tab} file ..."
  26. case $# in
  27.     0|1)
  28.     echo 'convert file contents by one of the following methods:
  29.     addcr - adds a carriage return in front of every line feed
  30.     delbs - deletes backspaces and bold or underline characters
  31.     delcr - deletes carriage returns from file
  32.     delff - deletes form feeds from file
  33.     b2ul  - converts boldface text in nroff output to underlined
  34.     cr2lf - converts carriage returns to line feeds
  35.     lf2cr - converts line feeds to carriage returns
  36.     indent - indents text 5 spaces
  37.     sp2tab - converts spaces to tabs via "unexpand"'
  38.     echo $usage; exit 1;;
  39. esac
  40.  
  41. function=$1
  42. shift
  43.  
  44. for x do
  45.     if test ! -f $x; then
  46.     echo "$x: not a file"
  47.     else
  48.     case $function in
  49.         addcr)    sed s/$/
  50.         delcr)    tr -d '\015' <$x >$x.$$;;
  51.         delff)    tr -d '\014' <$x >$x.$$;;
  52.         cr2lf)    tr '\015' '\012' <$x >$x.$$;;
  53.         lf2cr)    tr '\012' '\015' <$x >$x.$$;;
  54.         b2ul)    sed -e '/\.\.\./s//\_/g' $x >$x.$$;;
  55.         delbs)    sed s/_//g $x | sed s/.//g >$x.$$;;
  56.         dblsp)    sed "s:$::" $x | tr "\001" "\012" >$x.$$;;
  57.         indent)    sed '/./s/^/     /' $x >$x.$$;;
  58.         sp2tab)    unexpand -a <$x >$x.$$;;
  59.         *)    echo $usage; exit 1;;
  60.     esac
  61.     test -n $x.$$ && mv $x.$$ $x
  62.     fi
  63. done
  64.