how to list all python test scripts that contain “def test”
Want to list all python test scripts that contain "def test"
This command line did not work while individual command works
find . -name "*.py" | grep "def test"
grep find
New contributor
add a comment |
Want to list all python test scripts that contain "def test"
This command line did not work while individual command works
find . -name "*.py" | grep "def test"
grep find
New contributor
1
Perhapsfind -name *.py -print0 | xargs -0 grep 'def test
?
– Doug O'Neal
9 hours ago
add a comment |
Want to list all python test scripts that contain "def test"
This command line did not work while individual command works
find . -name "*.py" | grep "def test"
grep find
New contributor
Want to list all python test scripts that contain "def test"
This command line did not work while individual command works
find . -name "*.py" | grep "def test"
grep find
grep find
New contributor
New contributor
edited 11 hours ago
John1024
46.7k4110124
46.7k4110124
New contributor
asked 11 hours ago
Kam MokKam Mok
111
111
New contributor
New contributor
1
Perhapsfind -name *.py -print0 | xargs -0 grep 'def test
?
– Doug O'Neal
9 hours ago
add a comment |
1
Perhapsfind -name *.py -print0 | xargs -0 grep 'def test
?
– Doug O'Neal
9 hours ago
1
1
Perhaps
find -name *.py -print0 | xargs -0 grep 'def test
?– Doug O'Neal
9 hours ago
Perhaps
find -name *.py -print0 | xargs -0 grep 'def test
?– Doug O'Neal
9 hours ago
add a comment |
2 Answers
2
active
oldest
votes
Try:
grep -r --include '*.py' 'def test'
-r
tells grep to search for files recursively--include '*.py'
tells grep to only examine files whose names end in.py
.
The --include
option is supported by both GNU (Linux) grep and MacOS grep
Discussion of pipeline approach
In the following command, find passes the names of the files found to standard input of grep:
find . -name "*.py" | grep "def test"
The issue here is that grep treats its standard input as the text to search. Consequently, the only output will be those files whose name (as opposed to contents) contains def test
.
For example, let's create an empty file:
$ touch 'def test.py'
And run the pipeline command:
$ find . -name "*.py" | grep "def test"
./def test.py
The command finds this file because of its name. Its contents are never examined.
... if yourgrep
supports--include
like GNU grep does.
– Bodo
11 hours ago
add a comment |
find . -name '*.py' -exec grep -l 'def test' {} ;
5
you may want to considerfind . -name '*.py' -exec grep -l 'def test' {} +
to reduce the number ofgrep
invocations
– iruvar
10 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Kam Mok is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f500243%2fhow-to-list-all-python-test-scripts-that-contain-def-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try:
grep -r --include '*.py' 'def test'
-r
tells grep to search for files recursively--include '*.py'
tells grep to only examine files whose names end in.py
.
The --include
option is supported by both GNU (Linux) grep and MacOS grep
Discussion of pipeline approach
In the following command, find passes the names of the files found to standard input of grep:
find . -name "*.py" | grep "def test"
The issue here is that grep treats its standard input as the text to search. Consequently, the only output will be those files whose name (as opposed to contents) contains def test
.
For example, let's create an empty file:
$ touch 'def test.py'
And run the pipeline command:
$ find . -name "*.py" | grep "def test"
./def test.py
The command finds this file because of its name. Its contents are never examined.
... if yourgrep
supports--include
like GNU grep does.
– Bodo
11 hours ago
add a comment |
Try:
grep -r --include '*.py' 'def test'
-r
tells grep to search for files recursively--include '*.py'
tells grep to only examine files whose names end in.py
.
The --include
option is supported by both GNU (Linux) grep and MacOS grep
Discussion of pipeline approach
In the following command, find passes the names of the files found to standard input of grep:
find . -name "*.py" | grep "def test"
The issue here is that grep treats its standard input as the text to search. Consequently, the only output will be those files whose name (as opposed to contents) contains def test
.
For example, let's create an empty file:
$ touch 'def test.py'
And run the pipeline command:
$ find . -name "*.py" | grep "def test"
./def test.py
The command finds this file because of its name. Its contents are never examined.
... if yourgrep
supports--include
like GNU grep does.
– Bodo
11 hours ago
add a comment |
Try:
grep -r --include '*.py' 'def test'
-r
tells grep to search for files recursively--include '*.py'
tells grep to only examine files whose names end in.py
.
The --include
option is supported by both GNU (Linux) grep and MacOS grep
Discussion of pipeline approach
In the following command, find passes the names of the files found to standard input of grep:
find . -name "*.py" | grep "def test"
The issue here is that grep treats its standard input as the text to search. Consequently, the only output will be those files whose name (as opposed to contents) contains def test
.
For example, let's create an empty file:
$ touch 'def test.py'
And run the pipeline command:
$ find . -name "*.py" | grep "def test"
./def test.py
The command finds this file because of its name. Its contents are never examined.
Try:
grep -r --include '*.py' 'def test'
-r
tells grep to search for files recursively--include '*.py'
tells grep to only examine files whose names end in.py
.
The --include
option is supported by both GNU (Linux) grep and MacOS grep
Discussion of pipeline approach
In the following command, find passes the names of the files found to standard input of grep:
find . -name "*.py" | grep "def test"
The issue here is that grep treats its standard input as the text to search. Consequently, the only output will be those files whose name (as opposed to contents) contains def test
.
For example, let's create an empty file:
$ touch 'def test.py'
And run the pipeline command:
$ find . -name "*.py" | grep "def test"
./def test.py
The command finds this file because of its name. Its contents are never examined.
edited 7 hours ago
answered 11 hours ago
John1024John1024
46.7k4110124
46.7k4110124
... if yourgrep
supports--include
like GNU grep does.
– Bodo
11 hours ago
add a comment |
... if yourgrep
supports--include
like GNU grep does.
– Bodo
11 hours ago
... if your
grep
supports --include
like GNU grep does.– Bodo
11 hours ago
... if your
grep
supports --include
like GNU grep does.– Bodo
11 hours ago
add a comment |
find . -name '*.py' -exec grep -l 'def test' {} ;
5
you may want to considerfind . -name '*.py' -exec grep -l 'def test' {} +
to reduce the number ofgrep
invocations
– iruvar
10 hours ago
add a comment |
find . -name '*.py' -exec grep -l 'def test' {} ;
5
you may want to considerfind . -name '*.py' -exec grep -l 'def test' {} +
to reduce the number ofgrep
invocations
– iruvar
10 hours ago
add a comment |
find . -name '*.py' -exec grep -l 'def test' {} ;
find . -name '*.py' -exec grep -l 'def test' {} ;
answered 11 hours ago
BodoBodo
1,03219
1,03219
5
you may want to considerfind . -name '*.py' -exec grep -l 'def test' {} +
to reduce the number ofgrep
invocations
– iruvar
10 hours ago
add a comment |
5
you may want to considerfind . -name '*.py' -exec grep -l 'def test' {} +
to reduce the number ofgrep
invocations
– iruvar
10 hours ago
5
5
you may want to consider
find . -name '*.py' -exec grep -l 'def test' {} +
to reduce the number of grep
invocations– iruvar
10 hours ago
you may want to consider
find . -name '*.py' -exec grep -l 'def test' {} +
to reduce the number of grep
invocations– iruvar
10 hours ago
add a comment |
Kam Mok is a new contributor. Be nice, and check out our Code of Conduct.
Kam Mok is a new contributor. Be nice, and check out our Code of Conduct.
Kam Mok is a new contributor. Be nice, and check out our Code of Conduct.
Kam Mok is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f500243%2fhow-to-list-all-python-test-scripts-that-contain-def-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Perhaps
find -name *.py -print0 | xargs -0 grep 'def test
?– Doug O'Neal
9 hours ago