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

  • Home
  • SEARCH
  • 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 4268162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:59:52+00:00 2026-05-21T06:59:52+00:00

I am new to bash and am having difficulty processing directory tree structures. I

  • 0

I am new to bash and am having difficulty processing directory tree structures.
I have a directory structure that is as follows

I/A/dataA.dat
I/B/dataB.dat
I/C/dataC.dat

II/A/dataA.dat
II/B/dataB.dat
II/C/dataC.dat

III/A/dataA.dat
III/B/dataB.dat
III/C/dataC.dat

I now want to process I/A/dataA.dat with I/B/dataB.dat and likewise II/A/dataA.dat with II/B/dataB.dat etc (for every case). But I do not want to process, for example, I/A/dataA.dat with II/B/dataB.dat.

What is the best way to find such pairs of files?

I wish to pass the names of the found pair to a bash function such as follows

function process_pair()
{
  fileOne=$1; #for example II/A/data.dat
  fileTwo=$2; #for example II/B/data.dat
  //the rest of the function that processes this pair.
}

but I do not know how to get the variables $1 and $2.

I am currently using bash and starting from the dirs=find $SOURCE -type d -links 2 command (to find all the leaf directories – adapted from this question). I am then trying to loop over these (using substring commands to obtain the directory above).
However, I am finding this difficult and I think there must be a better way.

  • 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-05-21T06:59:52+00:00Added an answer on May 21, 2026 at 6:59 am

    Readily done in the shell:

    for dir in I II III; do
        subdirs=()
        for subdir in $dir/*; do subdirs+=("${subdir##*/}"); done
        for (( i=0 ;i<${#subdirs[*]}-1; i++ ));  do
            for (( j=i ;j<${#subdirs[*]} ;j++ ));  do
                a=${subdirs[$i]}
                b=${subdirs[$j]}
                process_pair $dir/$a/data$a.dat $dir/$b/data$b.dat
            done
        done
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an env var that's being set(PYTHONPATH) whenever I open a new Bash
I would like to create a new directory that its content is soft links
I have a piece of code that invokes an instance of the bash terminal
I'm quite new to bash scripting and i was having a look at permissions
I'm relatively new to bash scripting, having started out of the need to manage
I am new to bash and having a tough time figuring this out. Using
I have a bash script that tests whether the sftp connection exists, very simple
I'm having difficulty executing a batch file in Java that expects parameters. These parameters
I'm new to bash scripting and I'm having a hard time to figure out
I am pretty new to bash, and I want to include an env for

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.