LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-09-2019, 02:30 AM   #16
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,021

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343

Quote:
Originally Posted by bkelly View Post
I don't agree with that.
Unfortunately it is irrelevant. This is how it is working. I know you wanted something else, but grep can't read your mind (and even my mind).
Quote:
Originally Posted by bkelly View Post
By specifying a file limitation, such as *.cpp
You can't specify a file limitation. As it was already explained, *.cpp will be expanded by the shell before executing grep, so instead of *.cpp a list of files will be passed to grep. You can check it if you execute set -xv before this grep command.

Quote:
Originally Posted by bkelly View Post
As noted, and as I read the man page, it should work.
Unfortunately the command line parsing/evauluation is not part of grep (or any other command), it is made by the shell. This is some kind of preprocessing occurred unconditionally before the real execution. In windows this works differently.
To achieve what you need you need to implement something, because there is no such tool available (installed) by default. An example was already posted by smallpond.
 
Old 03-09-2019, 04:44 AM   #17
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by smallpond View Post
This is defined in my .bashrc for doing recursive grep. Maybe others have something better:

Code:
gfind () 
{ 
    if [ -z "$1" ]; then
        return;
    fi;
    find . -type f -exec grep -H "$1" \{} \; 2> /dev/null
}
You don't need the return, it can be simplified to
Code:
gfind()
{ 
   if [ "$1" ]; then
      find . -type f -exec grep -H "$1" \{} \; 2> /dev/null
   fi
}
and you could even extend it with a 2nd argument for the filenames you're doing the grep on
Code:
gfind()
{
   test "$2" && FILES="-name $2"
   if [ "$1" ]; then
      find . -type f "FILES" -exec grep -H "$1" \{} \; 2> /dev/null
   fi
}
 
Old 03-10-2019, 06:45 AM   #18
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by ehartman View Post
The thing is that "*.cpp" is evaluated BY the shell in the current directory only, before grep gets passed the commandline.
So grep will search recursively for the .cpp files that have the same name as the ones IN that current directory (no others).
As you went one dir upwards there were no .cpp files in that directory thus grep didn't have any filenames to search for.
as i already noted in post #10, but you said it better.
relevant information tends to get lost when op is too keen on complaining.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
Sorting recursive 'ls' and 'grep' SirTristan Linux - Newbie 5 03-13-2008 02:39 PM
non Recursive query and Recursive query prashsharma Linux - Server 1 06-27-2007 09:33 AM
recursive grep xpucto Solaris / OpenSolaris 2 05-29-2007 09:57 AM
Recursive grep jimieee Linux - General 5 10-06-2003 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration