How to find in different kinds of files

Clash Royale CLAN TAG#URR8PPP up vote
0
down vote
favorite
I'm working on a Ubuntu Windows app on my Windows-10 PC, the result of uname -a is the following:
Linux DOMINIQUEDS 4.4.0-17134-Microsoft #48-Microsoft Fri Apr 27 18:06:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
I'm doing some C++ development, and I'd like to know which source files (*.cpp or *.h) are including the file Sample.h, so I launched following command:
find ./ -name "*.cpp" -or -name "*.h" -exec grep -i "include" /dev/null ; | grep "Sample.h"
This seems not to be working: only the *.h files, containing include and Sample.h on the same line, are given.
However I know for sure that the -o construction for finding different kinds of files is correct:
find ./ -name "*.cpp" -or -name "*.h"
=> here I get a list of *.cpp and *.h files.
This leaves me with two possibilities:
- Either the behaviour is correct: the
-execparameter is only used on the lastfindresult. In that case, can somebody tell me how I can perform the-execon allfindresults? - Either the behaviour is wrong. In that case, does somebody know if this is a general Ubuntu problem/Windows-10 Ubuntu app problem/... and if any solution can be expected and when?
Thanks in advance
command-line find windows-subsystem-for-linux
add a comment |Â
up vote
0
down vote
favorite
I'm working on a Ubuntu Windows app on my Windows-10 PC, the result of uname -a is the following:
Linux DOMINIQUEDS 4.4.0-17134-Microsoft #48-Microsoft Fri Apr 27 18:06:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
I'm doing some C++ development, and I'd like to know which source files (*.cpp or *.h) are including the file Sample.h, so I launched following command:
find ./ -name "*.cpp" -or -name "*.h" -exec grep -i "include" /dev/null ; | grep "Sample.h"
This seems not to be working: only the *.h files, containing include and Sample.h on the same line, are given.
However I know for sure that the -o construction for finding different kinds of files is correct:
find ./ -name "*.cpp" -or -name "*.h"
=> here I get a list of *.cpp and *.h files.
This leaves me with two possibilities:
- Either the behaviour is correct: the
-execparameter is only used on the lastfindresult. In that case, can somebody tell me how I can perform the-execon allfindresults? - Either the behaviour is wrong. In that case, does somebody know if this is a general Ubuntu problem/Windows-10 Ubuntu app problem/... and if any solution can be expected and when?
Thanks in advance
command-line find windows-subsystem-for-linux
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm working on a Ubuntu Windows app on my Windows-10 PC, the result of uname -a is the following:
Linux DOMINIQUEDS 4.4.0-17134-Microsoft #48-Microsoft Fri Apr 27 18:06:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
I'm doing some C++ development, and I'd like to know which source files (*.cpp or *.h) are including the file Sample.h, so I launched following command:
find ./ -name "*.cpp" -or -name "*.h" -exec grep -i "include" /dev/null ; | grep "Sample.h"
This seems not to be working: only the *.h files, containing include and Sample.h on the same line, are given.
However I know for sure that the -o construction for finding different kinds of files is correct:
find ./ -name "*.cpp" -or -name "*.h"
=> here I get a list of *.cpp and *.h files.
This leaves me with two possibilities:
- Either the behaviour is correct: the
-execparameter is only used on the lastfindresult. In that case, can somebody tell me how I can perform the-execon allfindresults? - Either the behaviour is wrong. In that case, does somebody know if this is a general Ubuntu problem/Windows-10 Ubuntu app problem/... and if any solution can be expected and when?
Thanks in advance
command-line find windows-subsystem-for-linux
I'm working on a Ubuntu Windows app on my Windows-10 PC, the result of uname -a is the following:
Linux DOMINIQUEDS 4.4.0-17134-Microsoft #48-Microsoft Fri Apr 27 18:06:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
I'm doing some C++ development, and I'd like to know which source files (*.cpp or *.h) are including the file Sample.h, so I launched following command:
find ./ -name "*.cpp" -or -name "*.h" -exec grep -i "include" /dev/null ; | grep "Sample.h"
This seems not to be working: only the *.h files, containing include and Sample.h on the same line, are given.
However I know for sure that the -o construction for finding different kinds of files is correct:
find ./ -name "*.cpp" -or -name "*.h"
=> here I get a list of *.cpp and *.h files.
This leaves me with two possibilities:
- Either the behaviour is correct: the
-execparameter is only used on the lastfindresult. In that case, can somebody tell me how I can perform the-execon allfindresults? - Either the behaviour is wrong. In that case, does somebody know if this is a general Ubuntu problem/Windows-10 Ubuntu app problem/... and if any solution can be expected and when?
Thanks in advance
command-line find windows-subsystem-for-linux
edited May 15 at 9:12
muru
129k19271461
129k19271461
asked May 15 at 9:08
Dominique
1106
1106
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
However I know for sure that the -o construction for finding different
kinds of files is correct:find ./ -name "*.cpp" -or -name "*.h"
True, but the precedence of -or is not that high. From man find:
Please note that -a when specified implicitly (for example by two tests
appearing without an explicit operator between them) or explicitly has
higher precedence than -o. This means that find . -name afile -o -name
bfile -print will never print afile.
So:
-name "*.cpp" -or -name "*.h" -exec grep ...
Is like:
-name "*.cpp" -or ( -name "*.h" -exec grep ... )
And not like:
( -name "*.cpp" -or -name "*.h" ) -exec grep ...
You need:
find . ( -name '*.cpp' -o -name '*.h' ) -exec grep -H '#include.*Sample.h' +
(I assume you used /dev/null to make grep print the filename? The -H option does that.)
indeed, the/dev/nullis an old trick for showing the filename.
â Dominique
May 15 at 9:19
add a comment |Â
up vote
2
down vote
With modern grep, you don't need find at all e.g.
grep -r --include='*.cpp' --include='*.h' 'include' . | grep 'Sample.h'
or - better (given that the order of the search terms is unambiguous)
grep -r --include='*.cpp' --include='*.h' 'include.*Sample.h' .
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
However I know for sure that the -o construction for finding different
kinds of files is correct:find ./ -name "*.cpp" -or -name "*.h"
True, but the precedence of -or is not that high. From man find:
Please note that -a when specified implicitly (for example by two tests
appearing without an explicit operator between them) or explicitly has
higher precedence than -o. This means that find . -name afile -o -name
bfile -print will never print afile.
So:
-name "*.cpp" -or -name "*.h" -exec grep ...
Is like:
-name "*.cpp" -or ( -name "*.h" -exec grep ... )
And not like:
( -name "*.cpp" -or -name "*.h" ) -exec grep ...
You need:
find . ( -name '*.cpp' -o -name '*.h' ) -exec grep -H '#include.*Sample.h' +
(I assume you used /dev/null to make grep print the filename? The -H option does that.)
indeed, the/dev/nullis an old trick for showing the filename.
â Dominique
May 15 at 9:19
add a comment |Â
up vote
2
down vote
accepted
However I know for sure that the -o construction for finding different
kinds of files is correct:find ./ -name "*.cpp" -or -name "*.h"
True, but the precedence of -or is not that high. From man find:
Please note that -a when specified implicitly (for example by two tests
appearing without an explicit operator between them) or explicitly has
higher precedence than -o. This means that find . -name afile -o -name
bfile -print will never print afile.
So:
-name "*.cpp" -or -name "*.h" -exec grep ...
Is like:
-name "*.cpp" -or ( -name "*.h" -exec grep ... )
And not like:
( -name "*.cpp" -or -name "*.h" ) -exec grep ...
You need:
find . ( -name '*.cpp' -o -name '*.h' ) -exec grep -H '#include.*Sample.h' +
(I assume you used /dev/null to make grep print the filename? The -H option does that.)
indeed, the/dev/nullis an old trick for showing the filename.
â Dominique
May 15 at 9:19
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
However I know for sure that the -o construction for finding different
kinds of files is correct:find ./ -name "*.cpp" -or -name "*.h"
True, but the precedence of -or is not that high. From man find:
Please note that -a when specified implicitly (for example by two tests
appearing without an explicit operator between them) or explicitly has
higher precedence than -o. This means that find . -name afile -o -name
bfile -print will never print afile.
So:
-name "*.cpp" -or -name "*.h" -exec grep ...
Is like:
-name "*.cpp" -or ( -name "*.h" -exec grep ... )
And not like:
( -name "*.cpp" -or -name "*.h" ) -exec grep ...
You need:
find . ( -name '*.cpp' -o -name '*.h' ) -exec grep -H '#include.*Sample.h' +
(I assume you used /dev/null to make grep print the filename? The -H option does that.)
However I know for sure that the -o construction for finding different
kinds of files is correct:find ./ -name "*.cpp" -or -name "*.h"
True, but the precedence of -or is not that high. From man find:
Please note that -a when specified implicitly (for example by two tests
appearing without an explicit operator between them) or explicitly has
higher precedence than -o. This means that find . -name afile -o -name
bfile -print will never print afile.
So:
-name "*.cpp" -or -name "*.h" -exec grep ...
Is like:
-name "*.cpp" -or ( -name "*.h" -exec grep ... )
And not like:
( -name "*.cpp" -or -name "*.h" ) -exec grep ...
You need:
find . ( -name '*.cpp' -o -name '*.h' ) -exec grep -H '#include.*Sample.h' +
(I assume you used /dev/null to make grep print the filename? The -H option does that.)
answered May 15 at 9:17
muru
129k19271461
129k19271461
indeed, the/dev/nullis an old trick for showing the filename.
â Dominique
May 15 at 9:19
add a comment |Â
indeed, the/dev/nullis an old trick for showing the filename.
â Dominique
May 15 at 9:19
indeed, the
/dev/null is an old trick for showing the filename.â Dominique
May 15 at 9:19
indeed, the
/dev/null is an old trick for showing the filename.â Dominique
May 15 at 9:19
add a comment |Â
up vote
2
down vote
With modern grep, you don't need find at all e.g.
grep -r --include='*.cpp' --include='*.h' 'include' . | grep 'Sample.h'
or - better (given that the order of the search terms is unambiguous)
grep -r --include='*.cpp' --include='*.h' 'include.*Sample.h' .
add a comment |Â
up vote
2
down vote
With modern grep, you don't need find at all e.g.
grep -r --include='*.cpp' --include='*.h' 'include' . | grep 'Sample.h'
or - better (given that the order of the search terms is unambiguous)
grep -r --include='*.cpp' --include='*.h' 'include.*Sample.h' .
add a comment |Â
up vote
2
down vote
up vote
2
down vote
With modern grep, you don't need find at all e.g.
grep -r --include='*.cpp' --include='*.h' 'include' . | grep 'Sample.h'
or - better (given that the order of the search terms is unambiguous)
grep -r --include='*.cpp' --include='*.h' 'include.*Sample.h' .
With modern grep, you don't need find at all e.g.
grep -r --include='*.cpp' --include='*.h' 'include' . | grep 'Sample.h'
or - better (given that the order of the search terms is unambiguous)
grep -r --include='*.cpp' --include='*.h' 'include.*Sample.h' .
answered May 15 at 10:36
steeldriver
62.2k1196164
62.2k1196164
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036433%2fhow-to-find-in-different-kinds-of-files%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password