delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/06/10:37:46

Date: Sun, 6 Jul 1997 17:37:05 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Nate Eldredge <eldredge AT ap DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: Escaped chars in regexps
In-Reply-To: <199707041643.JAA18466@adit.ap.net>
Message-ID: <Pine.SUN.3.91.970706173623.8624J-100000@is>
MIME-Version: 1.0

On Fri, 4 Jul 1997, Nate Eldredge wrote:

> Does anybody know of a way to allow the use of escaped characters (\n, \b,
> \t for newline, backspace, tab) in regexps for `grep' and `sed'?

You can't.  These sequences aren't part of regexp syntax; you can have
them when you call regexp functions from a C program, but that's
because the compiler automatically converts any \t etc. in character
strings.

Why can't you just use the character itself?  For example, this works
for me:

	sed -n -e /^TAB/p Makefile

(where I actually pressed the TAB key inside the slashes).  This
command prints all the lines which begin with a TAB.

For characters such as BS (which cannot be easily typed on the
keyboard), create a text file with the Sed sommand using your favorite
editor and use it with -f:

	sed -f script ...

Any decent editor will allow you to put any ASCII character, including
a backspace, into a file.

(Incidentally, some keyboard enhancers actually allow you to type BS
verbatim using some kind of quote character; with Bash, use Ctrl-Q.)

- Raw text -


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