www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/07/22:47:50

From: myknees AT aol DOT com (Myknees)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: sed hates me
Date: 8 Jun 1998 02:33:58 GMT
Lines: 43
Message-ID: <1998060802335800.WAA17898@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
References: <357aae4b DOT 6492244 AT news1 DOT bway DOT net>
Organization: AOL http://www.aol.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <357aae4b DOT 6492244 AT news1 DOT bway DOT net>, jlrubin AT bway DOT net (Josh Rubin)
writes:

>Sed vewsion 1.18 doesn't seem to like backspaces in
>regular expressions. 

It depends on how you say "backspace" to sed.

>sed --expression='s/\b//g'  file > output 
>leaves backspaces untouched. - try it on a formatted man page.

While '\b' matches backspace in awk, it doesn't in sed.  There are a lot of
little differences between sed and awk, and escape sequences are often
different.  
One possible way to find ways to express "backspace" & other characters to sed
is to view a file in less.exe.  If you look at the formatted man page you
mention with less using the -U switch, or if you open the *.1 file in emacs,
you'll see that there are a bunch of ^H characters.  That is your clue that by
typing control-H, you generate the character "backspace".

The problem is that you need to be able to type that without the cursor going
backward.  In bash and under vi, you can do that by first typing control-v.  In
the DOS editor, EDIT, you can do that by first typing control-p.  Maybe someone
knows how to get a control-h character into an emacs buffer or onto a
command.com command line--I don't.

If you put control-H into the regexp instead of the backslash and 'b', sed will
match the backspace characters.

>sed --expression='s/x\b//g' 
>removes the 'x' but leaves the backspace!

sed -e 's/\(.\)^H\1/\1/g' -e 's/_^H\(.\)/\1/g' foo.1
Will remove much of the stuff from formatted man pages.  (Assuming they're real
control-h characters and not just carat-followed-by-h.)  You can tell how to
form the regexp by looking at the man page in emacs.

>Am I doing something wrong, or is this a sed bug, or
>this this specific to the DJGPP port?

It's a feature, I think.  sed isn't like awk.

--Ed (Myknees)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019