I have a code that is creating me a script where I can change the name of the titles of the sequences in a FASTA file. 

This is the text file I'm using: 

    #Assembly	Genome Center name	RefSeq Accession.version	GenBank Accession.version	NCBI name
    GeoFor_1.0	scaffold40	NW_005054297	JH739887	GPS_002009865
    GeoFor_1.0	scaffold112	NW_005054298	JH739888	GPS_002009866
    GeoFor_1.0	scaffold41	NW_005054299	JH739889	GPS_002009867
    GeoFor_1.0	scaffold130	NW_005054300	JH739890	GPS_002009868
    GeoFor_1.0	scaffold54	NW_005054301	JH739891	GPS_002009869
    GeoFor_1.0	scaffold16	NW_005054302	JH739892	GPS_002009870

This is the FASTA file that I'm using and that I want to change the names. AS you can see, I want to find the scaffold names that match the different JH######. 

    >Scaffold410	275
    TGCATTAATATGAGTGTGTGCTGCAAAAGTTCAGGTCATGGTCCGATCATACTTCACATTTTGGTAGCACTTTAAGCAGAGATCGGTTATCCCATTCTGTGGAAGACTCAACACTATCATAAGGTCCCACAGTTTTATTATCCCTCTGCCTCCCGGAATGCCCCCGGCAGTGAGGGGTACCATCTTCTCAGCAGTAAGGATATTCTTCAGGAGTTCCGTGTGAGCTTTCCCGGATTTAGTTCCATTTTTTAAATACTTCCCAATTCTTTGCTTTG
    >Scaffold430	374
    CTTTGTTAACTGAAAGAGCCTCTAAGTAGATGACCAGTGCTCAGTTAGTACAGTATGAATTTTGTTTAATGGAACAGGAAGATTTAGTATTGAGAAGCGGTTAAGGGTTTAACCCAGCCTCCTGTCTGAATGGACCTGAAGAGGGGGGCCGGGAAGAAACCCATGACTGCATTAAAGTGATAGATCTCCAGACATGGGCTAGGGAAGATTTACAAGACACTCCCTGGCCTGAGGGAGAAAATATGTTTATTGATGAGTCTTCAAGGGTGGCAGAAGGGAAGCGATTTACAGGATACACAATCATTAATGGAAGGAAATTAAAGGAAGGGGGGAGATTGTCACCCACCTGGTCAGTTCAGACAGCAGAGCTGTAT
    >Scaffold1010	597
    GGAACACACCTGGGCACACCTGGATGGAGCAGGAACACACCTGGATGGGGTTAGGACACATCTGGATGGCGTTGGGACACACCTGGATGCGCTCAGGGTACACCTG...

Thesis the command I use to create a script to change the names 

    tail -n +2 scaffold_names_2.txt | while read assemb gcenter refseq genbank ncbi; do echo -ne "sed 's/[[:<:]]$gcenter[[:>:]]/$genbank/g' | " >>script.sh; done

The problem is that I'm not able to save the fasta file with the new names. 

This is the last line of my script: 

    ... sed 's/[[:<:]]scaffold4469[[:>:]]/JH767125/g'  name.fasta.fa 

The script is running without error, but it's doing nothing. 

Do you know why? How can I change all the titles and save it as a new fasta file with another name ? 
It's very simple with [SeqKit][1], a cross-platform and ultrafast toolkit for FASTA/Q file manipulation.

Just one command:

    cat scaffolds.fasta | seqkit replace --ignore-case --kv-file <(cut -f 2,4 table.tsv) --pattern "^(\w+)" --replacement "{kv}"

Explanation:

SeqKit subcommand `replace` can find substrings with regular expression
 and replace them with strings or corresponding values of found substrings provided by the tab-delimited key-value file.

Therefore, the key-value data are firstly extracted by `cut -f 2,4 table.tsv`

    $ cut -f 2,4 table.tsv
    Genome  name
    scaffold410     JH739887
    scaffold430     JH739888

Then `seqkit replace` command is used to replace FASTA headers. `--pattern "^(\w+)"` refers to the to be replaced substrings (e.g., `Scaffold410`), and the special placeholder symbols `{kv}` represents the corresponding value of the key.

BTW, if you need similar manipulations of CSV/TSV files, [csvtk][2] provides similar functions and features


  [1]: http://bioinf.shenwei.me/seqkit/
  [2]: http://bioinf.shenwei.me/csvtk