首页 > 解决方案 > Find and replace a string in Perl

问题描述

I have the following command line:

perl -i -pe 's/_GSV*//g' file.fasta

My goal is change some sequences that have the following pattern:

GSVIVG01006342001_GSVIVT01006342001

I want to find all sequences that starts with _GSV and finish with anything (that`s why I put the '*') and substitute for nothing.

When I run my command it just recognize the _GSV and return to me that:

GSVIVG01006342001IVT01006342001

and I want that:

GSVIVG01006342001

Can anybody tell me what's wrong with my command line?

标签: perlbioinformatics

解决方案


before the *, include a dot that means any character

perl -i -pe 's/_GSV.*//g' file.fasta

You can also include the symbol $ to ensure you arrive until the end of the string

perl -i -pe 's/_GSV.*$//g' file.fasta

推荐阅读