Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8369337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:37:03+00:00 2026-06-09T13:37:03+00:00

I need a Bash Script to Execute a program for all directories that do

  • 0

I need a Bash Script to Execute a program for all directories that do not have a specific file and create the output file on the same directory.This program needs an input file which exist in every directory with the name *.DNA.fasta.Suppose I have the following directories that may contain sub directories also

dir1/a.protein.fasta  
dir2/b.protein.fasta  
dir3/anyfile  
dir4/x.orf.fasta

I have started by finding the directories that don’t have that specific file whic name is *.protein.fasta
in this case I want the dir3 and dir4 to be listed (since they do not contain *.protein.fasta)
I have tried this code:

find . -maxdepth 1  -type d  \! -exec test -e '{}/*protein.fasta' \; -print

but it seems I missed some thing it does not work.
also I do not know how to proceed for the whole story.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:37:04+00:00Added an answer on June 9, 2026 at 1:37 pm

    This is a tricky one.

    I can’t think of a good solution. But here’s a solution, nevertheless. Note that this is guaranteed not to work if your directory or file names contain newlines, and it’s not guaranteed to work if they contain other special characters. (I’ve only tested with the samples in your question.)

    Also, I haven’t included a -maxdepth because you said you need to search subdirectories too.

    #!/bin/bash
    
    # Create an associative array
    declare -A excludes
    
    # Build an associative array of directories containing the file
    while read line; do
      excludes[$(dirname "$line")]=1
      echo "excluded: $(dirname "$line")" >&2
    done <<EOT
    $(find . -name "*protein.fasta" -print)
    EOT
    
    # Walk through all directories, print only those not in array
    find . -type d \
    | while read line ; do
      if [[ ! ${excludes[$line]} ]]; then
        echo "$line"
      fi
    done
    

    For me, this returns:

    .
    ./dir3
    ./dir4
    

    All of which are directories that do not contain a file matching *.protein.fasta. Of course, you can replace the last echo "$line" with whatever you need to do with these directories.

    Alternately:

    If what you’re really looking for is just the list of top-level directories that do not contain the matching file in any subdirectory, the following bash one-liner may be sufficient:

    for i in *; do test -d "$i" && ( find "$i" -name '*protein.fasta' | grep -q . || echo "$i" ); done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash script which need to execute some php scripts and to
I have a bash script that I need to write my password to run
I need to have a script execute (bash or perl or php, any will
I need to execute a bash script on boot. To do so I created
I need to make a bash script that takes user input and does some
I need to output some text as bash script, but in a script. I
I need to write a quick bash script that asks the user which mac
I am working in a bash script where I need to analyze the output
I have a bash script. I need to look if text exists in the
i have this problem: I have created a bash script that performs some tasks.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.