Linux search for text in files of same name in multiple folders (maxdepth 2) and generate a report file












1















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.xmlin 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?










share|improve this question



























    1















    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.xmlin 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?










    share|improve this question

























      1












      1








      1








      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.xmlin 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?










      share|improve this question














      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.xmlin 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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 15 at 4:57









      JoeJoe

      286




      286






















          2 Answers
          2






          active

          oldest

          votes


















          1














          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...?






          share|improve this answer































            1














            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.






            share|improve this answer

























              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              1














              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...?






              share|improve this answer




























                1














                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...?






                share|improve this answer


























                  1












                  1








                  1







                  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...?






                  share|improve this answer













                  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...?







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 15 at 5:23









                  JoeJoe

                  286




                  286

























                      1














                      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.






                      share|improve this answer






























                        1














                        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.






                        share|improve this answer




























                          1












                          1








                          1







                          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.






                          share|improve this answer















                          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.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jan 15 at 7:41

























                          answered Jan 15 at 7:18









                          sudodussudodus

                          23.9k32874




                          23.9k32874






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                               ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕