bash for loop with two type of files
2
1
Entering edit mode
6.6 years ago
mbk0asis ▴ 660

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!

for-loop bash • 2.0k views
ADD COMMENT
4
Entering edit mode
6.6 years ago
5heikki 10k

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
ADD COMMENT
0
Entering edit mode
6.6 years ago
piet ★ 1.8k

In a bash script you may also use variable modifiers:

for f in ./*.seq; do
  echo ${f%.*} 
  echo ${f%.*}.seq
  echo ${f%.*}.param
done
ADD COMMENT

Login before adding your answer.

Traffic: 1416 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6