Replace fasta ID with value from TSV file (sed with special characters)
0
0
Entering edit mode
2.4 years ago
SaltedPork ▴ 170

Command:

sed -i "s/^>.*$/>$fastaid/g" output.fasta

The desired output is to replace the entire fasta ID with everything stored in the variable $fastaid.

Problem is that $fastaid looks like 12456789.AB.25/12/21 and it throws errors due to the special characters of . and /

How can I amend the sed command to accommodate special characters?

If there is an awk alternative that would be good as well.

sed • 795 views
ADD COMMENT
1
Entering edit mode
awk -vX="${fastaid}"  '/^>/ {printf(">%s\n",X);next;} {print;}'
ADD REPLY
0
Entering edit mode
$ cat file.fa 
>seq1
atgc

$ sed -r "s_^>.*\$_>12456789.AB.25/12/21_g" file.fa
>12456789.AB.25/12/21
atgc

Two cents: Please do not use i when you are testing or not sure.

ADD REPLY

Login before adding your answer.

Traffic: 2628 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