I have a bunch of files and a script which I run on them. That script takes 2 files as an input and all files are in this format: a.txt1 a.txt2
Now the script I use is like this: foo.sh a.txt1 a.txt2
I have to run this script run on 250 pairs (eg. a1.txt1 a1.txt2 to a250.txt1 a250.txt2)
I am doing this manually by entering file names. I was wondering is there any way to automate this process. All these pairs are in same folder, is there any way to loop the process on all pairs?
I hope I made it clear.
Thank you.
To be specific, these are some sample file names:
- T39_C.txt2
- T39_D.txt1
- T39_D.txt2
- T40_A.txt1
- T40_A.txt2
- T40_B.txt1
- T40_B.txt2
- T40_C.txt1
- T40_C.txt2
- T40_D.txt1
- T40_D.txt2
- unmatched.txt1
- unmatched.txt2
- WT11_A.txt1
- WT11_A.txt2
- WT11_B.txt1
- WT11_B.txt2
- WT11_C.txt1
Assuming all files are in pairs (ie,
<something>.txt1and<something>.txt2then you can do something line this:In line 3, we use a shell glob to grab all files ending with
.txt1. Line 4, we use a substitution to remove the final1and replace it with a2. And the real work is done in line 5.