grep problems

Hannu E K Nevalainen garbage_collector@telia.com
Mon Jun 14 09:12:00 GMT 2004


> From: Mark.Bevan@gwent.wales.nhs.uk
> Sent: Monday, June 14, 2004 9:47 AM

> All,
>
> I was having some trouble using grep to look for text in files.
>
> >From some tests it looks like meta characters cause the problem to show
> itself :

Well, the "meta characters" has a different meaning for the cygwin/bash
utilities - consider that. Read more below.

> C:\temp>type test.txt
> text
>
> C:\temp>grep test test.txt
> text
>
> C:\temp>grep text *.txt
> test.txt:text


The following test, below, seems to have one problem - to begin with; Your
use of backslash as path component separator.
 Remember cygwin+bash uses \ as an "escape character" i.e. this tells to use
the character after the slash "as is" - without any special meaning (if
there is such a meaning).
 Note also that depending on the context this "escaping" might be "reversed"
e.g; when running bash:
$ echo -e "Line1\nLine2\e[32mColored text\e[mNormal text"
 \n - gets replaced with a linefeed
 \e - gets replaced by the ESC-character (ASCII-code 27)
(read the output of "man echo" "help echo" and "info echo" for more)

You also seem to have misunderstood how paths in general are set up in
cygwin.
 Without really checking your cmd-lines, I'll go on saying this:
I don't think that \ has the same meaning for "grep" as you seem to think,
as indicated by your testing below.

 / alone stands for the root of the filesystem, as it is set up by "mount"
(in conjunction w disk partitioning on a real *ux machine)
What that corresponds to depends on your installation; e.g. my NONSTANDARD
setup has this;

C:\Program\Cygwin on / type system (binmode)

i.e. / is the same as the Win/DOS-path "C:\Program\Cygwin\"

Check your installation by just typing "mount" + enter; the output SHOULD
contain a line with the same " on / " as above. The text left of " on" is
the path that gets substituted for "/"
(and if I guess right for \ too - if the \ isn't used for escaping before
that happens. Some of your test below indicate that escaping happens)

I'd say that you'd have a lot less problems understanding what happens if
you stick to using 'rxvt' as console and 'bash' as shell (instead of the
windows cmd/command prompt+console window you're using now) and a full POSIX
style (path and all) on your command line entries.

Just add something like;
	rxvt -ls -e /usr/bin/bash --login -i &
as last command to your cygwin.bat - this will launch bash in rxvt.

To get more info regarding the use/setup of rxvt+bash: Use google.com on
"site:cygwin.com rxvt" - I bet you'll find a lot of information.


> C:\temp>grep text \temp\test.txt
> text
>
> C:\temp>grep text \temp\*.txt
> GREP: temp*.txt: No such file or directory
>
> C:\temp>grep text ..\temp\*.txt
> GREP: ..temp*.txt: No such file or directory
>
> C:\temp>grep text c:\temp\*.txt
> GREP: c:\temp\*.txt: No such file or directory
>
> C:\temp>grep text ../temp/*.txt
> ../temp/test.txt:hello
>
> C:\temp>grep text /temp/*.txt
> GREP: /temp/*.txt: No such file or directory
>
> C:\temp>grep text c:/temp/*.txt
> c:/temp/test.txt:text
>
> I have upgraded to latest release of Cygwin and this has not
> changed things.
> I have tried the above on a Windows 98 and Windows XP system as
> well - same
> results.
>
> Any ideas how I get around this problem ?


/Hannu E K Nevalainen, B.Sc. EE - 59+16.37'N, 17+12.60'E             --76-->

** on a mailing list; please keep replies on that particular list **

-- printf("LocalTime: UTC+%02d\n",(DST)? 2:1); --
--END OF MESSAGE--


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list