4

I would like to remove just the numbers and "_" after ">" symbol, for example:

>1_CR-B_CR56_t
MTKIIKFVYFMTIFISPNHHCPVYNCTHPKQPWCKLVRLQLLFHGSLIGLCDCI
>2_R-B_R46_t
MVEVTKLVNVMLIFLTLSPLVYDCQAYECELPFKPDCLMVEYSPQFVALRCGCV
>3000_N-N274_M
MVEVTKLVNVMLIFLTLFVYTDSDCQAYACELPFKPDCLMVEYAPQFFRLACGCV

Expected Results:

>CR-B_CR56_t
MTKIIKFVYFMTIFISPNHHCPVYNCTHPKQPWCKLVRLQLLFHGSLIGLCDCI
>R-B_R46_t
MVEVTKLVNVMLIFLTLSPLVYDCQAYECELPFKPDCLMVEYSPQFVALRCGCV
>N-N274_M
MVEVTKLVNVMLIFLTLFVYTDSDCQAYACELPFKPDCLMVEYAPQFFRLACGCV

I used sed "s/>[0-9][_]//g" but it removed ">" as well.

8

Just a slight modification from your sed command:

sed 's/^>[0-9]\+[_]/>/g'

the s is the sed substitute command, it searches for the string on the left hand side and replaces it with the string on the right hand side. Instead of replacing it with nothing you can replace it with the > character that you would like to keep.

^ is used to specify that the match should only start at the beginning of a newline

Additionally the * is being used to match more than a single digit.

  • thanks. I tried so many options, but not this one. – Paul Dec 13 '18 at 21:47
  • 3
    You might want the line-start anchor (^) as well. And \+ instead of * for one or more digits. – glenn jackman Dec 13 '18 at 21:56
1
awk '{sub(/^>._|^>...._/,">")}1' file
>CR-B_CR56_t
MTKIIKFVYFMTIFISPNHHCPVYNCTHPKQPWCKLVRLQLLFHGSLIGLCDCI
>R-B_R46_t
MVEVTKLVNVMLIFLTLSPLVYDCQAYECELPFKPDCLMVEYSPQFVALRCGCV
>N-N274_M
MVEVTKLVNVMLIFLTLFVYTDSDCQAYACELPFKPDCLMVEYAPQFFRLACGCV
0
command:sed 's/^>[0-9]\{1,9\}\_/>/g' filename

output

>CR-B_CR56_t
MTKIIKFVYFMTIFISPNHHCPVYNCTHPKQPWCKLVRLQLLFHGSLIGLCDCI
>R-B_R46_t
MVEVTKLVNVMLIFLTLSPLVYDCQAYECELPFKPDCLMVEYSPQFVALRCGCV
>N-N274_M
MVEVTKLVNVMLIFLTLFVYTDSDCQAYACELPFKPDCLMVEYAPQFFRLACGCV

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.