Linux: Recursively find all .txt files that don't have a matching .tif












2















I am using Debian Linux. I'm a newbie. I'll do my best to ask in the simplest way I know.



I have a pretty deep tree of directories on a drive that contain thousands of .tif files and .txt files. I'd like to recursively find (list) all .txt files that do not have a matching .tif file (basename). The .tif files and .txt files are also located in separate directories throughout the tree.



In simple form it could look like this...



directory1: hf-770.tif, hf-771.tif, hf-772.tif



directory2: hf-770.txt, hf-771.txt, hf-771.txt, hr-001.txt, tb-789.txt



I need to find (list) hr-001.txt and tb-789.txt as they do not have a matching .tif file. Again the directory tree is quite deep with multiple sub-directories throughout.



I researched and experimented with variations of the following commands but cannot seem to make it work. Thank you so much.



find -name "*.tif" -name "*.txt" | ls -1 | sed 's/([^.]*).*/1/' | uniq









share|improve this question





























    2















    I am using Debian Linux. I'm a newbie. I'll do my best to ask in the simplest way I know.



    I have a pretty deep tree of directories on a drive that contain thousands of .tif files and .txt files. I'd like to recursively find (list) all .txt files that do not have a matching .tif file (basename). The .tif files and .txt files are also located in separate directories throughout the tree.



    In simple form it could look like this...



    directory1: hf-770.tif, hf-771.tif, hf-772.tif



    directory2: hf-770.txt, hf-771.txt, hf-771.txt, hr-001.txt, tb-789.txt



    I need to find (list) hr-001.txt and tb-789.txt as they do not have a matching .tif file. Again the directory tree is quite deep with multiple sub-directories throughout.



    I researched and experimented with variations of the following commands but cannot seem to make it work. Thank you so much.



    find -name "*.tif" -name "*.txt" | ls -1 | sed 's/([^.]*).*/1/' | uniq









    share|improve this question



























      2












      2








      2








      I am using Debian Linux. I'm a newbie. I'll do my best to ask in the simplest way I know.



      I have a pretty deep tree of directories on a drive that contain thousands of .tif files and .txt files. I'd like to recursively find (list) all .txt files that do not have a matching .tif file (basename). The .tif files and .txt files are also located in separate directories throughout the tree.



      In simple form it could look like this...



      directory1: hf-770.tif, hf-771.tif, hf-772.tif



      directory2: hf-770.txt, hf-771.txt, hf-771.txt, hr-001.txt, tb-789.txt



      I need to find (list) hr-001.txt and tb-789.txt as they do not have a matching .tif file. Again the directory tree is quite deep with multiple sub-directories throughout.



      I researched and experimented with variations of the following commands but cannot seem to make it work. Thank you so much.



      find -name "*.tif" -name "*.txt" | ls -1 | sed 's/([^.]*).*/1/' | uniq









      share|improve this question
















      I am using Debian Linux. I'm a newbie. I'll do my best to ask in the simplest way I know.



      I have a pretty deep tree of directories on a drive that contain thousands of .tif files and .txt files. I'd like to recursively find (list) all .txt files that do not have a matching .tif file (basename). The .tif files and .txt files are also located in separate directories throughout the tree.



      In simple form it could look like this...



      directory1: hf-770.tif, hf-771.tif, hf-772.tif



      directory2: hf-770.txt, hf-771.txt, hf-771.txt, hr-001.txt, tb-789.txt



      I need to find (list) hr-001.txt and tb-789.txt as they do not have a matching .tif file. Again the directory tree is quite deep with multiple sub-directories throughout.



      I researched and experimented with variations of the following commands but cannot seem to make it work. Thank you so much.



      find -name "*.tif" -name "*.txt" | ls -1 | sed 's/([^.]*).*/1/' | uniq






      find-occurrences






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 20:35









      Robert

      2,15062535




      2,15062535










      asked Nov 24 '18 at 17:48









      allenjmallenjm

      132




      132
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can write a shell script for this:



          #!/bin/bash
          set -ue
          while IFS= read -r -d '' txt
          do
          tif=$(basename "$txt" | sed s/.txt$/.tif/)
          found=$(find . -name "$tif")
          if [ -z "$found" ]
          then
          echo "$txt has no tif"
          fi
          done < <(find . -name *.txt -print0)


          This has a loop over all .txt files it finds in the current directory or below. For each found file, it replaces the .txt extension with .tif, then tries to find that file. If it cannot find it (returned text is empty), it prints the .txt file name.



          robert@saaz:$ tree
          .
          ├── bar
          │   └── a.txt
          ├── foo
          │   ├── a.tif
          │   ├── b.tif
          │   ├── c.tif
          │   └── d.txt
          └── txt-without-tif

          2 directories, 6 files
          robert@saaz:$ bash txt-without-tif
          ./foo/d.txt has no tif





          share|improve this answer
























          • Did as you did.. ran the script on an example and it ran without a glitch. Running the script right now. Approx 600k files throughout multiple directories. Already receiving verbose output of .txt files that exist without a matching .tif. I will followup once the script has finished. Your programming expertise is greatly appreciated!

            – allenjm
            Nov 26 '18 at 0:13











          • I apologize for the delayed reply back. Your script worked perfectly and thank you. I tried to add a plus check to your response but seems I need 15 posts to change the score of your response. So if someone out there has a few minutes to give Robert a thumbs up I'd really appreciate it. Test as he did if you must. Thank you!

            – allenjm
            Dec 9 '18 at 21:59











          • @allenjm You can accept the answer, that will get us both points :-)

            – Robert
            Dec 9 '18 at 23:15











          • I didn't realize there's a difference between clicking on the up arrow and the check mark. I did as you suggested. Again thanks! The newbie is learning. :)

            – allenjm
            Dec 11 '18 at 0:58











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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%2fstackoverflow.com%2fquestions%2f53460860%2flinux-recursively-find-all-txt-files-that-dont-have-a-matching-tif%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can write a shell script for this:



          #!/bin/bash
          set -ue
          while IFS= read -r -d '' txt
          do
          tif=$(basename "$txt" | sed s/.txt$/.tif/)
          found=$(find . -name "$tif")
          if [ -z "$found" ]
          then
          echo "$txt has no tif"
          fi
          done < <(find . -name *.txt -print0)


          This has a loop over all .txt files it finds in the current directory or below. For each found file, it replaces the .txt extension with .tif, then tries to find that file. If it cannot find it (returned text is empty), it prints the .txt file name.



          robert@saaz:$ tree
          .
          ├── bar
          │   └── a.txt
          ├── foo
          │   ├── a.tif
          │   ├── b.tif
          │   ├── c.tif
          │   └── d.txt
          └── txt-without-tif

          2 directories, 6 files
          robert@saaz:$ bash txt-without-tif
          ./foo/d.txt has no tif





          share|improve this answer
























          • Did as you did.. ran the script on an example and it ran without a glitch. Running the script right now. Approx 600k files throughout multiple directories. Already receiving verbose output of .txt files that exist without a matching .tif. I will followup once the script has finished. Your programming expertise is greatly appreciated!

            – allenjm
            Nov 26 '18 at 0:13











          • I apologize for the delayed reply back. Your script worked perfectly and thank you. I tried to add a plus check to your response but seems I need 15 posts to change the score of your response. So if someone out there has a few minutes to give Robert a thumbs up I'd really appreciate it. Test as he did if you must. Thank you!

            – allenjm
            Dec 9 '18 at 21:59











          • @allenjm You can accept the answer, that will get us both points :-)

            – Robert
            Dec 9 '18 at 23:15











          • I didn't realize there's a difference between clicking on the up arrow and the check mark. I did as you suggested. Again thanks! The newbie is learning. :)

            – allenjm
            Dec 11 '18 at 0:58
















          1














          You can write a shell script for this:



          #!/bin/bash
          set -ue
          while IFS= read -r -d '' txt
          do
          tif=$(basename "$txt" | sed s/.txt$/.tif/)
          found=$(find . -name "$tif")
          if [ -z "$found" ]
          then
          echo "$txt has no tif"
          fi
          done < <(find . -name *.txt -print0)


          This has a loop over all .txt files it finds in the current directory or below. For each found file, it replaces the .txt extension with .tif, then tries to find that file. If it cannot find it (returned text is empty), it prints the .txt file name.



          robert@saaz:$ tree
          .
          ├── bar
          │   └── a.txt
          ├── foo
          │   ├── a.tif
          │   ├── b.tif
          │   ├── c.tif
          │   └── d.txt
          └── txt-without-tif

          2 directories, 6 files
          robert@saaz:$ bash txt-without-tif
          ./foo/d.txt has no tif





          share|improve this answer
























          • Did as you did.. ran the script on an example and it ran without a glitch. Running the script right now. Approx 600k files throughout multiple directories. Already receiving verbose output of .txt files that exist without a matching .tif. I will followup once the script has finished. Your programming expertise is greatly appreciated!

            – allenjm
            Nov 26 '18 at 0:13











          • I apologize for the delayed reply back. Your script worked perfectly and thank you. I tried to add a plus check to your response but seems I need 15 posts to change the score of your response. So if someone out there has a few minutes to give Robert a thumbs up I'd really appreciate it. Test as he did if you must. Thank you!

            – allenjm
            Dec 9 '18 at 21:59











          • @allenjm You can accept the answer, that will get us both points :-)

            – Robert
            Dec 9 '18 at 23:15











          • I didn't realize there's a difference between clicking on the up arrow and the check mark. I did as you suggested. Again thanks! The newbie is learning. :)

            – allenjm
            Dec 11 '18 at 0:58














          1












          1








          1







          You can write a shell script for this:



          #!/bin/bash
          set -ue
          while IFS= read -r -d '' txt
          do
          tif=$(basename "$txt" | sed s/.txt$/.tif/)
          found=$(find . -name "$tif")
          if [ -z "$found" ]
          then
          echo "$txt has no tif"
          fi
          done < <(find . -name *.txt -print0)


          This has a loop over all .txt files it finds in the current directory or below. For each found file, it replaces the .txt extension with .tif, then tries to find that file. If it cannot find it (returned text is empty), it prints the .txt file name.



          robert@saaz:$ tree
          .
          ├── bar
          │   └── a.txt
          ├── foo
          │   ├── a.tif
          │   ├── b.tif
          │   ├── c.tif
          │   └── d.txt
          └── txt-without-tif

          2 directories, 6 files
          robert@saaz:$ bash txt-without-tif
          ./foo/d.txt has no tif





          share|improve this answer













          You can write a shell script for this:



          #!/bin/bash
          set -ue
          while IFS= read -r -d '' txt
          do
          tif=$(basename "$txt" | sed s/.txt$/.tif/)
          found=$(find . -name "$tif")
          if [ -z "$found" ]
          then
          echo "$txt has no tif"
          fi
          done < <(find . -name *.txt -print0)


          This has a loop over all .txt files it finds in the current directory or below. For each found file, it replaces the .txt extension with .tif, then tries to find that file. If it cannot find it (returned text is empty), it prints the .txt file name.



          robert@saaz:$ tree
          .
          ├── bar
          │   └── a.txt
          ├── foo
          │   ├── a.tif
          │   ├── b.tif
          │   ├── c.tif
          │   └── d.txt
          └── txt-without-tif

          2 directories, 6 files
          robert@saaz:$ bash txt-without-tif
          ./foo/d.txt has no tif






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 20:47









          RobertRobert

          2,15062535




          2,15062535













          • Did as you did.. ran the script on an example and it ran without a glitch. Running the script right now. Approx 600k files throughout multiple directories. Already receiving verbose output of .txt files that exist without a matching .tif. I will followup once the script has finished. Your programming expertise is greatly appreciated!

            – allenjm
            Nov 26 '18 at 0:13











          • I apologize for the delayed reply back. Your script worked perfectly and thank you. I tried to add a plus check to your response but seems I need 15 posts to change the score of your response. So if someone out there has a few minutes to give Robert a thumbs up I'd really appreciate it. Test as he did if you must. Thank you!

            – allenjm
            Dec 9 '18 at 21:59











          • @allenjm You can accept the answer, that will get us both points :-)

            – Robert
            Dec 9 '18 at 23:15











          • I didn't realize there's a difference between clicking on the up arrow and the check mark. I did as you suggested. Again thanks! The newbie is learning. :)

            – allenjm
            Dec 11 '18 at 0:58



















          • Did as you did.. ran the script on an example and it ran without a glitch. Running the script right now. Approx 600k files throughout multiple directories. Already receiving verbose output of .txt files that exist without a matching .tif. I will followup once the script has finished. Your programming expertise is greatly appreciated!

            – allenjm
            Nov 26 '18 at 0:13











          • I apologize for the delayed reply back. Your script worked perfectly and thank you. I tried to add a plus check to your response but seems I need 15 posts to change the score of your response. So if someone out there has a few minutes to give Robert a thumbs up I'd really appreciate it. Test as he did if you must. Thank you!

            – allenjm
            Dec 9 '18 at 21:59











          • @allenjm You can accept the answer, that will get us both points :-)

            – Robert
            Dec 9 '18 at 23:15











          • I didn't realize there's a difference between clicking on the up arrow and the check mark. I did as you suggested. Again thanks! The newbie is learning. :)

            – allenjm
            Dec 11 '18 at 0:58

















          Did as you did.. ran the script on an example and it ran without a glitch. Running the script right now. Approx 600k files throughout multiple directories. Already receiving verbose output of .txt files that exist without a matching .tif. I will followup once the script has finished. Your programming expertise is greatly appreciated!

          – allenjm
          Nov 26 '18 at 0:13





          Did as you did.. ran the script on an example and it ran without a glitch. Running the script right now. Approx 600k files throughout multiple directories. Already receiving verbose output of .txt files that exist without a matching .tif. I will followup once the script has finished. Your programming expertise is greatly appreciated!

          – allenjm
          Nov 26 '18 at 0:13













          I apologize for the delayed reply back. Your script worked perfectly and thank you. I tried to add a plus check to your response but seems I need 15 posts to change the score of your response. So if someone out there has a few minutes to give Robert a thumbs up I'd really appreciate it. Test as he did if you must. Thank you!

          – allenjm
          Dec 9 '18 at 21:59





          I apologize for the delayed reply back. Your script worked perfectly and thank you. I tried to add a plus check to your response but seems I need 15 posts to change the score of your response. So if someone out there has a few minutes to give Robert a thumbs up I'd really appreciate it. Test as he did if you must. Thank you!

          – allenjm
          Dec 9 '18 at 21:59













          @allenjm You can accept the answer, that will get us both points :-)

          – Robert
          Dec 9 '18 at 23:15





          @allenjm You can accept the answer, that will get us both points :-)

          – Robert
          Dec 9 '18 at 23:15













          I didn't realize there's a difference between clicking on the up arrow and the check mark. I did as you suggested. Again thanks! The newbie is learning. :)

          – allenjm
          Dec 11 '18 at 0:58





          I didn't realize there's a difference between clicking on the up arrow and the check mark. I did as you suggested. Again thanks! The newbie is learning. :)

          – allenjm
          Dec 11 '18 at 0:58


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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%2fstackoverflow.com%2fquestions%2f53460860%2flinux-recursively-find-all-txt-files-that-dont-have-a-matching-tif%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

          Lallio

          Futebolista

          Jornalista