title: Automatically rename fasta files with the ID of the first sequence in each file
body: <p>I have multiple fasta files with single sequence in the same directory. I want to rename each fasta file with the header of the single sequence present in the fasta file. When i run my code , i obtain "Substitution pattern not terminated at (user-supplied code)"</p>
  
  <p>my code:</p>
  
  <pre><code>#!/bin/bash
  
  for i in /home/maryem/files/;
  do 
    if [ ! -f $i ]; then 
       echo "skipping $i"; 
    else 
       newname=`head -1 $i | sed 's/^\s*\([a-zA-Z0-9]\+\).*$/\1/'`; 
       [ -n "$newname" ] ; 
        mv -i $i $newname.fasta || echo "error at: $i"; 
    fi; 
  done | rename s/ // *.fasta
  </code></pre>
  
  <p>fasta file:</p>
  
  <pre><code>&gt;NC_013361.1 Escherichia coli O26:H11 str. 11368 DNA, complete genome
  AGCTTTTCATTCTGACTGCAATGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTCTCTGACAGCAGCTTCTGAACTG
  GTTACCTGCCGTGAGTAAATTAAAATTTTATTGACTTAGGTCACTAAATACTTTAACCAATATAGGCATAGCGCACAGAC
  AGATAAAAATTACAGAGTACACAACATCCATGAAACGCATTAGCACCACCATTATCACCACCATCACCATTACCACAGGT
  </code></pre>
  
  <p>I'm not sure if there is another way to rename each file with the ID in the header ??</p>