Question: bash for loop with two type of files
1
gravatar for mbk0asis
4.7 years ago by
mbk0asis570
Korea, Republic Of
mbk0asis570 wrote:

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?

Thanks you!

 

bash for loop • 1.5k views
ADD COMMENTlink modified 4.7 years ago by piet1.8k • written 4.7 years ago by mbk0asis570
4
gravatar for 5heikki
4.7 years ago by
5heikki9.0k
Finland
5heikki9.0k wrote:

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 COMMENTlink modified 4.7 years ago • written 4.7 years ago by 5heikki9.0k
0
gravatar for piet
4.7 years ago by
piet1.8k
planet earth
piet1.8k wrote:

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 COMMENTlink written 4.7 years ago by piet1.8k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1301 users visited in the last hour