Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Jul 2001 21:14:33 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Philipp Gaschutz <pg@philipp.de.com>
Cc:        Mikhail Teterin <mi@aldan.algebra.com>, questions@FreeBSD.ORG
Subject:   Re: AW: grep and \t (\r, etc.)
Message-ID:  <20010719211433.A14600@student.uu.se>
In-Reply-To: <BOELLCONIBKCLEHPNCDDKEGACNAA.pg@philipp.de.com>
References:  <200107191814.f6JIEwO34105@aldan.algebra.com> <BOELLCONIBKCLEHPNCDDKEGACNAA.pg@philipp.de.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jul 19, 2001 at 08:17:26PM +0200, Philipp Gaschutz wrote:
> Hi!
> 
> > 	find . -type -name '*.htm*' | xargs grep -E '\r$'
> > 
> > just keeps listing all lines which end with ``r''... Any clues?
> 
> Have you tried to replace ' with " ?
> or ... \\r ?

Won't help. If you check the manpage for grep you will see that the
regular expressions it use don't know anything about control characters
(including carriage return.)

One solution is to make sure that the search pattern which gets passed to
grep contains an actual carriage return. (Then grep will match that
character literally just as it would with any normal character.)
The following little C program will invoke grep in such a manner.
It takes one filename as an argument which is then passed on to grep as
the file to search through.
It could be invoked instead of "grep -E '\r$'" above as long as you only
pass it one filename at a time.



#include <unistd.h>
#include <stdlib.h>

char * args[] = 
	{
	"grep",
	"\015$",
	NULL,
	NULL
	};

char * envp[] =
	{
	NULL
	};	

int main(int argc,char *argv[])
	{
	if(argc < 2) return EXIT_FAILURE;
	args[2] = argv[1];
	
	execve("/usr/bin/grep",args,envp);
	exit(EXIT_FAILURE);
	}







-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010719211433.A14600>