0

I have what I guess is a pretty basic question about linux. Let us say I have I series of files, which run in couples. Each couple of files is the input of my command, which produces a single output. Then a would like to execute the same command with the following couple, producing a new output.

Let us say, for the example, that I have four files: F1.R1, F1.R2, F2.R1, and F2.R2

My first command would be:

myfunction F1.R1 F1.R2 -output F1

And the second:

myfunction F2.R1 F2.R2 -output F2

I would like to produce a command so that all couples are treated sequentially until all files are processed.

Thanks a lot for your help. Best

1 Answer 1

1

Loop over the .R1 files, replace R1 with R2 to get the other filename from the pair, then execute the command.

for file in *.R1
do
    file2=${file/.R1/.R2}
    output=${file%.R1}
    myfunction "$file" "$file2" --output "$output"
done
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Barmar, THANKS A LOT. It works for me. I had to tune it a little bit cause *. was giving me trouble, so that I had to use plain *, with no dot. Thanks again.
I don't understand that. If the filename is F1.R1 it should be matched by *.R1. Do you have files like F1R1 with no .?
Hi Barmar. I agree, and I did not go deeper into that, because it worked for me without the ".". I will certainly be confronted to a similar situation soon enough, so I'll check it out then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.