LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   anything piped to grep returns "(standard input)"... why? (http://www.linuxquestions.org/questions/linux-software-2/anything-piped-to-grep-returns-standard-input-why-672343/)

allohakdan 09-25-2008 01:56 PM

anything piped to grep returns "(standard input)"... why?
 
For some reason I cannot pipe anything to grep on one of my machines. All it gives back is "(standard input)"...

- some examples -

$ ps ax | grep "ps ax"
(standard input)

$ ls | grep -v myfile
(standard input)

I thought it might be something in my .bashrc file, but the only thing i had aliased grep to was "grep -color". To add to my frustration, using grep itself does work...

$ grep "something" myfile
myfile

I tried searching around, but so far I have no answers...

This machine is actually a virtual machine i have been using as a mobile test server (for about a year now) for testing out code and scripts on occasion... but recently i have been using it for more day to day work and thats when i realized there was a problem

Does anyone have an idea what is causing this or how I could fix it?

Thanks

ilikejam 09-25-2008 02:07 PM

That's a bit on the odd side.

What do you get from 'type grep'?

Dave

darthaxul 09-25-2008 05:23 PM

woa
 
I had something similar.
I think its either because the files are binary or they are not complete/fragmented?

allohakdan 09-26-2008 02:43 PM

$ type grep
grep is aliased to `grep -n -color'

ilikejam 09-27-2008 01:28 PM

Try doing 'unalias grep' and see if it works.

Dave

jgallo 09-27-2008 01:34 PM

any luck?

I had experienced this recently and am just not on the terminal where i had the problem, jsut wondering if these solutions work

Linux Archive

David the H. 09-27-2008 02:17 PM

Small tip for you: if you have an alias that's the same as the original command name, i.e. aliased to add flags or whatnot, you can use a backslash in front of the command to temporarily bypass the alias and revert to the default behavior.

e.g. if you have the alias ls="ls --all", then typing "\ls" will give you the original non-aliased "ls" output.

Likewise, typing "\grep" should allow you to bypass the alias in the case above. And it certainly appears to be the alias that's the problem, because I tried setting it up myself, and it does the same thing for me. But it works when I bypass the alias.


Edit: I think I see the problem. "grep -color" is not a valid command. The proper command is "grep --color=[when]", where "[when]" is either never, always, or auto.

allohakdan 09-28-2008 01:42 PM

$ ps ax | \grep "px ax"
7224 pts/4 R+ 0:00 px ax
7225 pts/4 R+ 0:00 grep ps ax

Thanks for the help! I was not aware that I could add the \ before my aliased commands to bypass the alias - nice trick. And yes you were both correct, the aliased syntax was the problem. I had noticed the syntax wasn't normal earlier but then wrote it off as not hurting anything because I _could_ grep individual files... next time I will be more careful

David the H. 09-28-2008 02:02 PM

Glad to help. And I myself wasn't aware that there was a "color" option for grep, so I learned something new also. :D


All times are GMT -5. The time now is 06:50 AM.