Article View: comp.unix.shell
Article #1517file conversion (was Re: How to strip edit characters)
From: Michael Prusynski
Date: Wed, 17 Oct 1990 22:04
Date: Wed, 17 Oct 1990 22:04
49 lines
2168 bytes
2168 bytes
With the recent discussion on stripping ^H and ^M etc. from files,
I thought I'd contribute my general purpose "cnvt" shell script.
Bill Pfiefer was the originator of this program, but I've modified it
and added to it quite a bit. The "delbs" function is for nroff output,
and also deletes the underscore or bold character. b2ul is not guaranteed.
The type of conversion you want must be the first argument.
---------- cut here -----------
: cnvt - Michael Prusynski - July,1987
PATH=/bin:$PATH
usage="usage: cnvt {addcr,delbs,delcr,delff,b2u,cr2lf,lf2cr,indent,sp2tab} file ..."
case $# in
0|1)
echo 'convert file contents by one of the following methods:
addcr - adds a carriage return in front of every line feed
delbs - deletes backspaces and bold or underline characters
delcr - deletes carriage returns from file
delff - deletes form feeds from file
b2ul - converts boldface text in nroff output to underlined
cr2lf - converts carriage returns to line feeds
lf2cr - converts line feeds to carriage returns
indent - indents text 5 spaces
sp2tab - converts spaces to tabs via "unexpand"'
echo $usage; exit 1;;
esac
function=$1
shift
for x do
if test ! -f $x; then
echo "$x: not a file"
else
case $function in
addcr) sed s/$/
delcr) tr -d '\015' <$x >$x.$$;;
delff) tr -d '\014' <$x >$x.$$;;
cr2lf) tr '\015' '\012' <$x >$x.$$;;
lf2cr) tr '\012' '\015' <$x >$x.$$;;
b2ul) sed -e '/\.\.\./s//\_/g' $x >$x.$$;;
delbs) sed s/_//g $x | sed s/.//g >$x.$$;;
dblsp) sed "s:$::" $x | tr "\001" "\012" >$x.$$;;
indent) sed '/./s/^/ /' $x >$x.$$;;
sp2tab) unexpand -a <$x >$x.$$;;
*) echo $usage; exit 1;;
esac
test -n $x.$$ && mv $x.$$ $x
fi
done
Technical Details
Message-ID:
<3846@wrgate.WR.TEK.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!rutgers!usc!sdd.hp.com!samsung!uunet!zephyr.ens.tek.com!wrgate!dadla!michaelpShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!rutgers!usc!sdd.hp.com!samsung!uunet!zephyr.ens.tek.com!wrgate!dadla!michaelp From: michaelp@dadla.WR.TEK.COM (Michael Prusynski) Newsgroups: comp.unix.shell Subject: file conversion (was Re: How to strip edit characters) Keywords: uses sed, tr, unexpand Message-ID: <3846@wrgate.WR.TEK.COM> Date: 17 Oct 90 22:04:00 GMT Sender: news@wrgate.WR.TEK.COM Lines: 49