unable to use grep use grep command in Centos 7

Comments, suggestions, compliments, etc
Post Reply
sharingan
Posts: 24
Joined: 2019/04/26 12:44:13

unable to use grep use grep command in Centos 7

Post by sharingan » 2020/06/16 14:33:49

Hi All,

currently i am using centos 7 , while using grep unable to get any result same issue with piping .
Please advice

tunk
Posts: 779
Joined: 2017/02/22 15:08:17

Re: unable to use grep use grep command in Centos 7

Post by tunk » 2020/06/16 14:37:08

More info please, e.g. what are your commands?

User avatar
TrevorH
Forum Moderator
Posts: 29644
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: unable to use grep use grep command in Centos 7

Post by TrevorH » 2020/06/16 14:55:05

Be specific, what did you run, what did you expect to find, show the line from the target file containing the string you were looking for as well as the exact command you ran that did not work.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

sharingan
Posts: 24
Joined: 2019/04/26 12:44:13

Re: unable to use grep use grep command in Centos 7

Post by sharingan » 2020/06/16 15:05:20

Hi

i using a simple searching and piping comnd : find . -type f | grep (character) .
But its showing no result no error message as well , for reference added the screen shot
Attachments
grep not working.PNG
grep not working.PNG (46.04 KiB) Viewed 864 times

tunk
Posts: 779
Joined: 2017/02/22 15:08:17

Re: unable to use grep use grep command in Centos 7

Post by tunk » 2020/06/16 15:47:12

Your find command will list all files, not the content of them.
You could look at the fgrep command.

MartinR
Posts: 608
Joined: 2015/05/11 07:53:27
Location: UK

Re: unable to use grep use grep command in Centos 7

Post by MartinR » 2020/06/16 15:55:22

Please do not use screen shots, cut and paste into a code (</>) block. Otherwise anyone trying to help you has to copy type which is liable to put people off.

Now to your problem. If you do a plain:

Code: Select all

find . -type f
./copy2.txt
./copy3.txt
./test1.txt
You can see that the output of the find command is a list of file names, that is three strings Now think about the pipeline, it is passing this output to the input of the grep, essentially:

Code: Select all

echo "./copy2.txt" | grep we
I would hope it is clear that the substring "we" occurs nowhere in the string "./copy2.txt".

Try:

Code: Select all

$ find . -type f -exec grep we '{}' \;
We should be do that , we are going.
Note the '{}' which tells find to inset the file name at that point, the execute the command. Do not forget the \; at the end or find will not know where the command ends. Have a read of the man page, it's all explained there.

sharingan
Posts: 24
Joined: 2019/04/26 12:44:13

Re: unable to use grep use grep command in Centos 7

Post by sharingan » 2020/06/17 06:37:43

Thanks for the help , i got it perfectly , and i am very sorry for the attachment .

User avatar
jlehtone
Posts: 3082
Joined: 2007/12/11 08:17:33
Location: Finland

Re: unable to use grep use grep command in Centos 7

Post by jlehtone » 2020/06/17 07:41:03

Grep can recurse directory. No find is needed:

Code: Select all

grep -r we .

MartinR
Posts: 608
Joined: 2015/05/11 07:53:27
Location: UK

Re: unable to use grep use grep command in Centos 7

Post by MartinR » 2020/06/17 08:17:17

Neat. It only goes to show that us "old hands" ought to re-read the simple stuff from time to time - sometimes "that's the way I've done it for 20 years" is not always the most efficient! More seriously, that is great for simple searches, but remember that find has powerful selection mechanisms for more advanced searches.

User avatar
jlehtone
Posts: 3082
Joined: 2007/12/11 08:17:33
Location: Finland

Re: unable to use grep use grep command in Centos 7

Post by jlehtone » 2020/06/17 09:26:34

The "File and Directory Selection" of man grep has some options, but yes, far from what find can.

There must be a way to find out, when such features have been injected into the code. Open source and all.

Post Reply

Return to “User Comments”