This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Find and replace

I have 3 files,

  1. a gbff3 file (Main file) with some accessions wrong
  2. a text file with list of wrong accessions
  3. a text file with list of write accessions to be replaced in place of wrong once in File 1

I tried it with while loop but couldn't declare 3 variables.

I was trying like this

While read line   
do     
 sed 's/$file2/$file3/g'  File1    
done > output    

But it didn't work .

Can you please let me know why it didn't work. And if not this then what will work.

sed while loop replace find

If I understand, it hould be something like

paste file1.txt file2.txt | awk '{printf("s/%s/%s/g\n",$1,$2);}' > tmp.sed

and then :

sed -f tmp.sed file1

BUT that's not that simple and it's dangerous. 1) if you have any '/' in your file 2) if you have identifiers like GENE111111 and GENE1 -> they both share the same prefix and could be both replaced.

0 answers

No answers yet.

Log in to answer this question.