Cygwin doesn't seem to end with grep command

1

I used to use grep on cygwin on windows XP successfully. All of a sudden, now when I run grep, it never seems to end.

miname@mycomputer /cygdrive/c/emacs
$ grep "lkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkj"

I've searched google but found nothing relating to this. I restarted my computer. I've also checked logs, but there seems to only be the setup log (in var/log). I seem to remember I had difficulty installing cygwin (I have a fairly locked down work computer) so would rather not reinstall (if indeed that would fix it).

What can I do to fix or investigate my problem?

EDIT: Having read the answer, I realised what I thought had been successful was really grep "asdfasdf" . - note the dot! I was not doing the same thing.

cammil

Posted 2013-11-13T17:09:00.473

Reputation: 234

Answers

3

There's no actual problem. What's happening here is that, since you haven't specified any files for grep to search, it is listening to STDIN for text to search. This is how pipelines such as tail -f /var/log/messages | grep "error" work: the tail command sends its output to grep's standard input, and grep prints only lines which match the given search string (in this example, "error").

If you invoke grep without files and without piping anything to it, it will inherit the standard input stream from your terminal, and listen to your keyboard. (Try it! Type something and press Return, and you'll see it echoed if it matches the search string you gave grep.) To terminate the grep process, press Control-C. To get useful output from it, pass it one or more files as command line arguments following the search string, e.g. grep "something" file.c file.h, or pipe something into it as in the tail example above.

This is how Unix grep works, and how it has always worked. If you used to invoke grep this way, and it behaved differently, then what you were invoking wasn't Cygwin's grep but some other utility, which happened to have the same name and live in a directory which came before Cygwin's /bin in your $PATH.

Aaron Miller

Posted 2013-11-13T17:09:00.473

Reputation: 8 849