bash for loop with two type of files
Hello, everyone!
I have two types of files ".seq" and ".param". One has sequence info (obviously) and the other has parameters for PRIMER3.
I have about 100 files with those extensions.
For example,
File1.seq File1.param
File2.seq File2.param
File3.seq File3.param
File4.seq File4.param
File5.seq File5.param
I was trying to concatenate files with the same name using 'for loop' and 'cat', but it didn't seem to work. The code I was going to try
for I in ./*.seq ./*.param
do cat $i # I'm stuck here. I don't think $i can take both files.
Is there a way to load two variables in a single loop, or am I doing completely wrong?
Thank you!
• 3,022 views
•
link
2 answers
One way is to get basename for one file and then append extension, e.g.
for F in *.seq, do N=$(basename "$F" .seq); cat $F "$N".param > "$N".out; done
• 0 views
•
link
In a bash script you may also use variable modifiers:
for f in ./*.seq; do
echo ${f%.*}
echo ${f%.*}.seq
echo ${f%.*}.param
done
• 0 views
•
link
Log in to answer this question.