Linux search for text in files of same name in multiple folders (maxdepth 2) and generate a report file
Situation:
In Linux, I have a parent folder with 22 folders of various names, each with a file of a particular name asset.xml
. Also in these folders are hundreds of other folders with asset.xml
in them, but these are previous versions and I'm not interested in them. I need to search inside each file for 3 tags "legend|assetID|name"
and return the information inside these tags. They're usually on the same line so i think Grep
is ok.
What i've tried:
grep -nr -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This takes way too long and return way too much duplicated data, so this isn't practical.
find . -maxdepth 2 -exec grep -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This returned an error with -exec missing an argument, so the output file was empty.
find . -maxdepth 2 -| grep -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This returned an empty output file.
Question:
How do I go through each like-named file each inside various-named folders (which also have other subfolders with files of the same name) and extract information inside the 3 tags and write this data into an output file?
playonlinux grep
add a comment |
Situation:
In Linux, I have a parent folder with 22 folders of various names, each with a file of a particular name asset.xml
. Also in these folders are hundreds of other folders with asset.xml
in them, but these are previous versions and I'm not interested in them. I need to search inside each file for 3 tags "legend|assetID|name"
and return the information inside these tags. They're usually on the same line so i think Grep
is ok.
What i've tried:
grep -nr -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This takes way too long and return way too much duplicated data, so this isn't practical.
find . -maxdepth 2 -exec grep -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This returned an error with -exec missing an argument, so the output file was empty.
find . -maxdepth 2 -| grep -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This returned an empty output file.
Question:
How do I go through each like-named file each inside various-named folders (which also have other subfolders with files of the same name) and extract information inside the 3 tags and write this data into an output file?
playonlinux grep
add a comment |
Situation:
In Linux, I have a parent folder with 22 folders of various names, each with a file of a particular name asset.xml
. Also in these folders are hundreds of other folders with asset.xml
in them, but these are previous versions and I'm not interested in them. I need to search inside each file for 3 tags "legend|assetID|name"
and return the information inside these tags. They're usually on the same line so i think Grep
is ok.
What i've tried:
grep -nr -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This takes way too long and return way too much duplicated data, so this isn't practical.
find . -maxdepth 2 -exec grep -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This returned an error with -exec missing an argument, so the output file was empty.
find . -maxdepth 2 -| grep -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This returned an empty output file.
Question:
How do I go through each like-named file each inside various-named folders (which also have other subfolders with files of the same name) and extract information inside the 3 tags and write this data into an output file?
playonlinux grep
Situation:
In Linux, I have a parent folder with 22 folders of various names, each with a file of a particular name asset.xml
. Also in these folders are hundreds of other folders with asset.xml
in them, but these are previous versions and I'm not interested in them. I need to search inside each file for 3 tags "legend|assetID|name"
and return the information inside these tags. They're usually on the same line so i think Grep
is ok.
What i've tried:
grep -nr -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This takes way too long and return way too much duplicated data, so this isn't practical.
find . -maxdepth 2 -exec grep -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This returned an error with -exec missing an argument, so the output file was empty.
find . -maxdepth 2 -| grep -E "legend|assetID|name" . > /dir/to/the/ReportFile.txt
This returned an empty output file.
Question:
How do I go through each like-named file each inside various-named folders (which also have other subfolders with files of the same name) and extract information inside the 3 tags and write this data into an output file?
playonlinux grep
playonlinux grep
asked Jan 15 at 4:57
JoeJoe
286
286
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I just found the solution.
grep -nr -E "legend|assetID|name" /dir/to/the/*/asset.xml > /dir/to/the/ReportFile.txt
The *
in the path is the "wildcard" I needed to go through each directory. I think it only goes to that directory and not into any deeper folder...?
add a comment |
Your command line with find
was almost correct :-)
The file(s) found by find
is represented by {}
. The -exec
part of the find command line must be finished somehow, with ;
or often better with +
which invokes grep
only once, and I suggest that you run grep
only on normal files -type f
, try
find . -maxdepth 2 -type f -exec grep -E "legend|assetID|name" {} + > ../output
You may want to specify the file name asset.xml
find . -maxdepth 2 -type f -name asset.xml -exec grep -E "legend|assetID|name" {} + > ../output
Check the result with
cat ../output
You may want to modify the maxdepth to 3 or whatever is suitable.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
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%2faskubuntu.com%2fquestions%2f1109818%2flinux-search-for-text-in-files-of-same-name-in-multiple-folders-maxdepth-2-and%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
I just found the solution.
grep -nr -E "legend|assetID|name" /dir/to/the/*/asset.xml > /dir/to/the/ReportFile.txt
The *
in the path is the "wildcard" I needed to go through each directory. I think it only goes to that directory and not into any deeper folder...?
add a comment |
I just found the solution.
grep -nr -E "legend|assetID|name" /dir/to/the/*/asset.xml > /dir/to/the/ReportFile.txt
The *
in the path is the "wildcard" I needed to go through each directory. I think it only goes to that directory and not into any deeper folder...?
add a comment |
I just found the solution.
grep -nr -E "legend|assetID|name" /dir/to/the/*/asset.xml > /dir/to/the/ReportFile.txt
The *
in the path is the "wildcard" I needed to go through each directory. I think it only goes to that directory and not into any deeper folder...?
I just found the solution.
grep -nr -E "legend|assetID|name" /dir/to/the/*/asset.xml > /dir/to/the/ReportFile.txt
The *
in the path is the "wildcard" I needed to go through each directory. I think it only goes to that directory and not into any deeper folder...?
answered Jan 15 at 5:23
JoeJoe
286
286
add a comment |
add a comment |
Your command line with find
was almost correct :-)
The file(s) found by find
is represented by {}
. The -exec
part of the find command line must be finished somehow, with ;
or often better with +
which invokes grep
only once, and I suggest that you run grep
only on normal files -type f
, try
find . -maxdepth 2 -type f -exec grep -E "legend|assetID|name" {} + > ../output
You may want to specify the file name asset.xml
find . -maxdepth 2 -type f -name asset.xml -exec grep -E "legend|assetID|name" {} + > ../output
Check the result with
cat ../output
You may want to modify the maxdepth to 3 or whatever is suitable.
add a comment |
Your command line with find
was almost correct :-)
The file(s) found by find
is represented by {}
. The -exec
part of the find command line must be finished somehow, with ;
or often better with +
which invokes grep
only once, and I suggest that you run grep
only on normal files -type f
, try
find . -maxdepth 2 -type f -exec grep -E "legend|assetID|name" {} + > ../output
You may want to specify the file name asset.xml
find . -maxdepth 2 -type f -name asset.xml -exec grep -E "legend|assetID|name" {} + > ../output
Check the result with
cat ../output
You may want to modify the maxdepth to 3 or whatever is suitable.
add a comment |
Your command line with find
was almost correct :-)
The file(s) found by find
is represented by {}
. The -exec
part of the find command line must be finished somehow, with ;
or often better with +
which invokes grep
only once, and I suggest that you run grep
only on normal files -type f
, try
find . -maxdepth 2 -type f -exec grep -E "legend|assetID|name" {} + > ../output
You may want to specify the file name asset.xml
find . -maxdepth 2 -type f -name asset.xml -exec grep -E "legend|assetID|name" {} + > ../output
Check the result with
cat ../output
You may want to modify the maxdepth to 3 or whatever is suitable.
Your command line with find
was almost correct :-)
The file(s) found by find
is represented by {}
. The -exec
part of the find command line must be finished somehow, with ;
or often better with +
which invokes grep
only once, and I suggest that you run grep
only on normal files -type f
, try
find . -maxdepth 2 -type f -exec grep -E "legend|assetID|name" {} + > ../output
You may want to specify the file name asset.xml
find . -maxdepth 2 -type f -name asset.xml -exec grep -E "legend|assetID|name" {} + > ../output
Check the result with
cat ../output
You may want to modify the maxdepth to 3 or whatever is suitable.
edited Jan 15 at 7:41
answered Jan 15 at 7:18
sudodussudodus
23.9k32874
23.9k32874
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1109818%2flinux-search-for-text-in-files-of-same-name-in-multiple-folders-maxdepth-2-and%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