Ask Your Question

Is grep broken, or am I broken?

asked 2016-03-14 14:16:10 -0600

walben gravatar image

updated 2016-03-15 18:03:28 -0600

I cannot upload an image so I'll just write the output and commands.


$ grep [Joes5] resturants.txt


smart, Parks, seafood, 6834948,9


steakhouse,Nelson Eye,Grill,6361017,8




$ grep *,5 resturants.txt

output: nothing

$ grep * resturants.txt

output: again, nothing

$ grep Joes5 resturants.txt

output: nothing


$ grep 5 resturants.txt




I encountered the same problem with debian, which is the main reason I decided to try out fedora instead. I consulted this problem with my linux teacher, and he couldn't figure this out either. PS: I updated my system today. I haven't used grep for a while now, so it may lie in some new version of /etc/grep.

So the question is: Am I doing overlooking some basics? Is grep not taking multiple patterns (*)? or is grep supposed to act like this?

PPS: the color scheme in fedora shows that the output findings comes from characters, as if I was searching for certain letters, not a certain pattern.

edit: It's mostly these commands that I'm worried about:

$ grep *,5 resturants.txt

$ grep * resturants.txt

they do not output anything.

edit retag flag offensive close merge delete


Welcome to ask.fedora. You might want to run unalias grep to get rid of the distracting colors that the fedora devs assume everybody wants. Also, you might want to run which grep to find out where the binary actually is. (hint: it's not in /etc) It would also help if you'd edit your post to add some formatting, as it's hard to see just what's happening right now.

sideburns gravatar imagesideburns ( 2016-03-14 15:03:14 -0600 )edit

+1 for that, please format your post a little bit so it's more readable. I really can't figure out what is going on with current formating ;-)

masteroman gravatar imagemasteroman ( 2016-03-14 15:56:20 -0600 )edit

Good that you formatted this better. Bottom line, grep was working and continues to work. You need to look more carefully at your usage to understand that it was/is working correctly.

dnl gravatar imagednl ( 2016-03-15 09:35:38 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-03-15 00:12:33 -0600

jmt gravatar image

I think neither are broken. You just have to find more about the inner workings of grep.

Your first example grep [Joes5] resturants.txt makes grep use a regular expression that matches any of the characters inside the square brackets. In a standard invocation grep understands a few of such expressions, but you can modify the behaviour of grep with various switches.

Take good look at the grep manual with man grep and especially info grep

edit flag offensive delete link more

answered 2016-03-15 00:10:14 -0600

dnl gravatar image

It would help if you show the complete contents of the restaurants.txt file. Also, as noted in earlier comment, please try to format your output so we can understand what output is on a single line v. across multiple lines.

As for the regular expressions: "[Joes5]" will search every line in restaurants.txt for any of the characters "J", "o", "e", "s", or "5" and color each distinct character occurrence; ",5" will look for that string (unless you happen to have a file that matches the glob ",5", like "fred,5" does; "*" will be replaced with the name of every file in the current directory; "Joes5" will look for the specific string "Joes5"; and finally "5" will search for every line with a "5" in the line.

If I look at your output, I'll guess grep did what you asked it to do. What are you actually trying to do?

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-03-14 14:16:10 -0600

Seen: 206 times

Last updated: Mar 15 '16