Answers.Body: <p>If all of your <code>.tf.txt</code> and <code>.tt.txt</code> files are in the same directory, the following command should work.</p>
  
  <pre><code>for tffile in $(ls *.tf.txt)
  do
      prefix=$(basename $tffile .tf.txt)
      join ${prefix}.tf.txt ${prefix}.tt.txt &gt; ${prefix}_final.txt
  done
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-10T20:24:12.323Z
Answers.Text: The `basename` call can be avoided by anchoring a regex with parameter expansion like so: `join ${tffile} ${tffile/%.tf.txt/.tt.txt} > ${tffile/%.tf.txt/_final.txt}`
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-11T13:16:08.707Z
Answers.Text: @RamRS Cool! I guess it's up to the individual to decide which ugly solution is less ugly! :-)
Answers.UserDisplayName: Daniel Standage
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-11T14:14:53.310Z
Answers.Text: Indeed. I wonder if `$()` is more performant than `${//}`.
Answers.UserDisplayName: Ram RS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-11T18:29:44.363Z
Answers.Text: @ Ram RS: 
  I am getting this error
           ${tffile/%.tf.txt/_final.txt}: ambiguous redirect
Answers.UserDisplayName: Riya
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-10T18:42:46.477Z
Answers.LastActivityDate: 2019-07-10T18:42:46.477Z
Answers.UserDisplayName: Daniel Standage
Body: <p>I have two types of files for a gene in a folder</p>
  
  <p>File 1: FOS.tf.txt </p>
  
  <pre><code>ABL2
  ACTN4
  ADGRE5
  ADIPOR2
  ADRB2
  ERCC4
  EZR
  FAS
  FMO4
  </code></pre>
  
  <p>File 2: FOS.tt.txt</p>
  
  <pre><code>ABL2
  CASP9
  CCK
  DDIT3
  ERCC4
  EZR
  FAS
  FMO4
  </code></pre>
  
  <p>After running command </p>
  
  <pre><code>join FOS.tf.txt FOS.tt.txt &gt; FOS_final.txt
  </code></pre>
  
  <p>I got output file: FOS_final.txt</p>
  
  <pre><code>ABL2
  ERCC4
  EZR
  FAS
  FMO4
  </code></pre>
  
  <p>My question is that I have these two type of files (tf and tt) for 605 genes in a folder and I want to run join command together for all my genes and get 605 output files.</p>
  
Tags: <bash>
Title: How to run 'join' command for multiple files (of 2 types) in a folder
ThreadText: # How to run 'join' command for multiple files (of 2 types) in a folder
  
  (Asked by: username_0 on 2019-07-10)
  
  I have two types of files for a gene in a folder
  
  File 1: FOS.tf.txt
  
  ```
  ABL2
  ACTN4
  ADGRE5
  ADIPOR2
  ADRB2
  ERCC4
  EZR
  FAS
  FMO4
  
  ```
  
  File 2: FOS.tt.txt
  
  ```
  ABL2
  CASP9
  CCK
  DDIT3
  ERCC4
  EZR
  FAS
  FMO4
  
  ```
  
  After running command
  
  ```
  join FOS.tf.txt FOS.tt.txt > FOS_final.txt
  
  ```
  
  I got output file: FOS\_final.txt
  
  ```
  ABL2
  ERCC4
  EZR
  FAS
  FMO4
  
  ```
  
  My question is that I have these two type of files (tf and tt) for 605 genes in a folder and I want to run join command together for all my genes and get 605 output files.
  
  **Tags:** bash
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-07-10. Score: 1 | Accepted answer
  
  If all of your `.tf.txt` and `.tt.txt` files are in the same directory, the following command should work.
  
  ```
  for tffile in $(ls *.tf.txt)
  do
      prefix=$(basename $tffile .tf.txt)
      join ${prefix}.tf.txt ${prefix}.tt.txt > ${prefix}_final.txt
  done
  
  ```
  
  > **Comments:**
  > **username_2**: The `basename` call can be avoided by anchoring a regex with parameter expansion like so: `join ${tffile} ${tffile/%.tf.txt/.tt.txt} > ${tffile/%.tf.txt/_final.txt}`  
  > **username_1**: @username_2 Cool! I guess it's up to the individual to decide which ugly solution is less ugly! :-)  
  > **username_2**: Indeed. I wonder if `$()` is more performant than `${//}`.  
  > **username_0**: @ username_2:  I am getting this error          ${tffile/%.tf.txt/_final.txt}: ambiguous redirect  
  
  ---
  
  