Find and replace
0
0
Entering edit mode
2.1 years ago
Ap1438 ▴ 50

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 • 534 views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 1860 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6