🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.shell
1 messages
1 total messages Started by Michael Prusynski Wed, 17 Oct 1990 22:04
file conversion (was Re: How to strip edit characters)
#1517
Author: Michael Prusynski
Date: Wed, 17 Oct 1990 22:04
49 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads