regexp on stdin

regexp on stdin

Post by m_stiefenho.. » Fri, 08 Sep 2000 20:19:41



I want to match piped lines from stdin against a
regular expression. As far as I know I can't use
expr, because the two arguments must be provided
as string and you can't use a hyphen as
substitute for stdin...

Does anybody know a workaround for this?

regards
Marek

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

regexp on stdin

Post by Vilmos Sot » Sat, 09 Sep 2000 00:38:50



> I want to match piped lines from stdin against a
> regular expression. As far as I know I can't use
> expr, because the two arguments must be provided
> as string and you can't use a hyphen as
> substitute for stdin...

It is not clear what you want. Maybe this?

echo Hello world | grep '[Hh]ello'

        ^                 ^
will be stdin          regexp

Vilmos

 
 
 

regexp on stdin

Post by Andrew N. McGuir » Sun, 10 Sep 2000 15:16:18


On Thu, 7 Sep 2000, Vilmos Soti quoth:

~~ Date: Thu, 07 Sep 2000 15:38:50 GMT

~~ Newsgroups: comp.os.linux.misc
~~ Subject: Re: regexp on stdin
~~
~~
~~ > I want to match piped lines from stdin against a
~~ > regular expression. As far as I know I can't use
~~ > expr, because the two arguments must be provided
~~ > as string and you can't use a hyphen as
~~ > substitute for stdin...
~~
~~ It is not clear what you want. Maybe this?
~~
~~ echo Hello world | grep '[Hh]ello'

Use Perl:

echo hello, world | perl -wne 'print if /[Hh]ello/'

I think you will find Perl's regular expressions to be more
powerful than most.

anm
--
BEGIN{ $^W = 0 }; $\ = $/; $$_ = $_ for qw~just another perl hacker~;
my $J = sub { return \$just }; my $A = sub { return \$another };
my $P = sub { return \$perl }; my $H = sub { return \$hacker  };
print map ucfirst() . " " => ${&$J()}, ${&$A()}, ${&$P()}, ${&$H()};

 
 
 

1. Help with regexp and find

I trying to write a find command that will list all files ending in .c or .pc

My best guess is

find . -name "*.[p*]c" -print

My description of the above command is

list all files that match:-
anything, followed by a dot, followed by any number of p's, followed by c

But only seems to list .pc files.

I know there are work arounds, like use another -name, or even pipe
into anopther grep, but I'm sure this can be made to work, somehow!!

--
Rob

We are Borg sheep, resistance is futile, you will be... Ooh look, fresh
grass.

( careful of spambait in email address if replying )

2. Gazel card (ISDN:Numéris) -> Help

3. Regexp Question

4. ISDN Teles S0 PCI

5. simple regexp

6. WTMP and WTMPX files

7. delting last occurence of a regexp

8. 3 Apache/Squid Developer Jobs

9. regex(S) & regexp(S) confusion ?!?

10. src/regexp question with circmflex "^"

11. regexp for email addr.

12. mod_rewrite regexp problem

13. sed regexp question