Ronald Robertson

Sanjay Singh

Scientist/Writer
  • Emailsanjaysingh765@gmail.com
  • Socail@lampatlex
  • VisitorSince 1982
  • LocationKentucky, USA



Get multiple strings from a file and replace them in another file with AWK





Get multiple strings from a file and replace them in another file



I have multiple strings (old strings) and their sustitution (new strings) in tab limited format in a file named as string. I want to replace them in another file named as Inputfile and save in Outfile. 



Script


awk '
NR==FNR {
old[NR] = $1
gsub(/&/,RS,$2)
new[NR] = $2
next
}
{
for (i=1; i in old; i++) {
gsub(old[i],new[i])
}
gsub(RS,"\\&")
print
}
' string Inputfile >Outfile





Extract Part of a FASTA Sequences with Position by python script HERE


Terminal screenshot





Comments