1752808 Members
6238 Online
108789 Solutions
New Discussion юеВ

Re: Grep

 
vimalj
Occasional Contributor

Grep

i am facing a problem with grep
in my server there are 2 users abc abc1
when i login as abc the following thing does not work
$ grep c*
c
cc
..
as the i/p(c,cc,..) matches the regular expression c* i should get the o/p i.e grep must echo back the i/p
But thats not the case
Whereas when i login as abc1 the things are fine.
The . files in both users home directory are same.
Even the shell is same.
Can somebody help me out.
7 REPLIES 7
Steven Schweda
Honored Contributor

Re: Grep

> i am facing a problem with grep

That's one way to look at it.

> $ grep c*

What, exactly, do you expect this to do?
What, exactly, are you trying to do?

man grep

> The . files in both users home directory
> are same.

Who cares?

echo c*

Are _those_ the same?
Ismail Azad
Esteemed Contributor

Re: Grep

Hi,

Please explain what is grep c*!! I don't understand how grep works without a filename as an argument. The command you have executed should typically generate a core file and prob killed by a signal.

Help me understand!
When you do a grep c*, where are you searching for the pattern that contains c*?



Regards
Read, read and read... Then read again until you read "between the lines".....
Steven Schweda
Honored Contributor

Re: Grep

> [...] The command you have executed should
> typically generate a core file and prob
> killed by a signal. [...]

Let's not get carried away. It may not make
much sense, but it could easily work (in
some sense). For example:

alp$ ls -l
total 2
-rw-r----- 1 SMS 40 2 Nov 11 23:35 c
-rw-r----- 1 SMS 40 26 Nov 11 23:34 c1
-rw-r----- 1 SMS 40 31 Nov 11 23:35 c2
-rw-r----- 1 SMS 40 15 Nov 11 23:40 c3

alp$ grep c*
c1:This file contains a "c".
c2:This file also contains a "c".

I don't understand what's desired here, and
I suspect that this command is useless, but
that doesn't mean that the command is pure
poison.
Steven Schweda
Honored Contributor

Re: Grep

> echo c*

In my example, of course:

alp$ echo c*
c c1 c2 c3

so:

grep c*

is equivalent to:

grep c c1 c2 c3

which is easy to demonstrate:

alp$ grep c c1 c2 c3
c1:This file contains a "c".
c2:This file also contains a "c".

(The command is still pretty useless, but
"grep" does what it's told.)
vimalj
Occasional Contributor

Re: Grep

Listen
I am testing my regular expressions using
grep c*.
I m providing the text from keyboard
The text that matches my regular expression is echoed back on screen
for e.g
grep c*
c #i/p text
c #o/p of grep as c matches c*

did u get what i need?
Dennis Handly
Acclaimed Contributor

Re: Grep

>did you get what I need?

Just about ALL REs need to be quoted. Unless you tell the shell not to do globbing.
grep "c*"

Re: Grep

Do you want to grep "c*" or do you want to grep "c" ?
In your example you should not get a match when you use "c*" .
Looks like you are mixing up pattern matching with Regular Expressions used in grep with pattern matching in `ls` (globbing: http://en.wikipedia.org/wiki/Glob_%28programming%29