Mail Archives: djgpp/1997/07/06/10:37:46
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 -