title: Replace header of one column by file name
body: <p>I have about 100 comma-separated text files with eight columns.</p>
  
  <p>Example of two file names:</p>
  
  <pre><code>sample1_sorted_count_clean.csv 
  sample2_sorted_count_clean.csv
  </code></pre>
  
  <p>Example of file content:</p>
  
  <pre><code>Domain,Phylum,Class,Order,Family,Genus,Species,Count
  Bacteria,Proteobacteria,Alphaproteobacteria,Sphingomonadales,Sphingomonadaceae,Zymomonas,Zymomonas mobilis,0.0
  Bacteria,Bacteroidetes,Flavobacteria,Flavobacteriales,Flavobacteriaceae,Zunongwangia,Zunongwangia profunda,0.0
  </code></pre>
  
  <p>For each file, I would like to replace the column header "Count" by sample ID, which is contained in the first part of the file name (sample1, sample2)</p>
  
  <p>In the end, the header should then look like this:</p>
  
  <pre><code>Domain,Phylum,Class,Order,Family,Genus,Species,sample1
  </code></pre>
  
  <p>If I use my code, the header looks like this:</p>
  
  <pre><code>Domain,Phylum,Class,Order,Family,Genus,Species,${f%_clean.csv}
  </code></pre>
  
  <pre><code>for f in *_clean.csv; do echo ${f}; sed -e "1s/Domain,Phylum,Class,Order,Family,Genus,Species,RPMM/Domain,Phylum,Class,Order,Family,Genus,Species,${f%_clean.csv}/" ${f} &gt; ${f%_clean.csv}_clean2.csv; done
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>for f in *_clean.csv; do gawk -F"," '{$NF=","FILENAME}1' ${f}  &gt; t &amp;&amp; mv t ${f%_clean.csv}_clean2.csv; done
  </code></pre>
  
  <p>In this case, "count" is replaced by the entire file name, but each row of the column contains file name now. The count values are no longer present. This is not what I want.</p>
  
  <p>Do you have any ideas on what else I may try?
  Thank you very much in advance!</p>
  
  <p>Anna</p>