[comp.unix.shell] How to strip edit characters

ejmag@aplcen.apl.jhu.edu (4680) (09/27/90)

Occasionally I receive mail from others which contains editing
characters such as backspace(^H).  When this text is printed to the
screen it appears fine, but when I try to edit it, I see all the edit
characters like sew^H^Ho (instead of "so").

Is there a "shell" way to remove the backspace characters, yet retain
the text in its final form?

One method I have successfully used on a graphics terminal is to cat
the file to the screen, and then use copy/paste from a window manager
to paste the final text into a new file.  This is ok, but I don't
always have access to a graphics workstation.

Any solutions?

-- 
Eric Magnusson
ejmag@aplcen.apl.jhu.edu

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (09/27/90)

In article <6665@aplcen.apl.jhu.edu> ejmag@aplcen (Magnusson Eric 859-4680) writes:
: Occasionally I receive mail from others which contains editing
: characters such as backspace(^H).  When this text is printed to the
: screen it appears fine, but when I try to edit it, I see all the edit
: characters like sew^H^Ho (instead of "so").
: 
: Is there a "shell" way to remove the backspace characters, yet retain
: the text in its final form?

Try filtering through either of

	col -b
	perl -pe '1 while s/.\010//'

The col command may do extra transmogrifications to the text that you
don't want.  The perl command may do extra transmogrifications to your
mind that you don't want.

Larry

pfalstad@phoenix.Princeton.EDU (Paul John Falstad) (09/27/90)

In article <6665@aplcen.apl.jhu.edu> ejmag@aplcen (Magnusson Eric 859-4680) writes:
>Is there a "shell" way to remove the backspace characters, yet retain

sed /.^H/s///g

You should be able to type in the ^H by typing <control-v><control-h>.
I had to fight with my terminal to keep it from sending ^?.

Perl solutions, anyone?  :-)

If Lafontaine's elk would spurn Tom Jones, the engine must be our head, the
dining car our esophagus, the guardsvan our left lung, the kettle truck our
shins, the first class compartment the piece of skin at the nape of the neck,
and the level crossing an electric elk called Simon.

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (09/28/90)

In article <2856@idunno.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul John Falstad) writes:
: In article <6665@aplcen.apl.jhu.edu> ejmag@aplcen (Magnusson Eric 859-4680) writes:
: >Is there a "shell" way to remove the backspace characters, yet retain
: 
: sed /.^H/s///g

Won't work.  Think what happens on "abc^H^H^H".

I wasn't going to post a sed solution because it looked to be messy, but
it would need to be something like

    sed ':top
	/.^H/{
	s///
	b top
    }'

or, a little more efficiently, if there are multiple ^H fields,

    sed ':top
	/[^^H]^H/{
	s///g
	b top
    }'

You ought to be able to use

    sed ':top
	s/[^^H]^H//g
	t top'

but t is buggy some locales.

Larry

jeff@onion.pdx.com (Jeff Beadles) (10/06/90)

In <6665@aplcen.apl.jhu.edu> ejmag@aplcen (Magnusson Eric 859-4680) writes:

...
>Is there a "shell" way to remove the backspace characters, yet retain
>the text in its final form?
...

Well, for systems that have it, the "col" command works just fine.  Use it as a
pipeline, ie:

col -b < input_yuch_o_file > neat_o_file


	-Jeff
-- 
Jeff Beadles	jeff@onion.pdx.com