sed with regular expression

upendra

I am trying to replace three letter code at the end of a sequence with nothing (basically removing) with sed but is not working well for multiple regex pattern. Here is an example of sequences

GCAAAAAGTTGTATAGTCACACAACCTAGACTTATATCGTCTGCTATTCATTAG
GCAAAAAGTTGTATAGTCACACAACCTAGACTTATATCGTCTGCTATTCATTAA
GCAAAAAGTTGTATAGTCACACAACCTAGACTTATATCGTCTGCTATTCATTGA

When I try to use regex individually with sed it works

echo "GCAAAAAGTTGTATAGTCACACAACCTAGACTTATATCGTCTGCTATTCATTAG" | sed 's/TAG$//'
echo "GCAAAAAGTTGTATAGTCACACAACCTAGACTTATATCGTCTGCTATTCATTAA" | sed 's/TAA$//'
echo "GCAAAAAGTTGTATAGTCACACAACCTAGACTTATATCGTCTGCTATTCATTAG" | sed 's/TAG$//'

However when I try to include multiple regex it doesn't work

echo "GCAAAAAGTTGTATAGTCACACAACCTAGACTTATATCGTCTGCTATTCATTAG" |
sed 's/(TAG$|TAA$|TGA$)//'

Could somebody point to me where I am doing wrong?

anubhava

You need to use extended regex switch in sed:

sed -r 's/(TAG|TAA|TGA)$//'

OR on OSX:

sed -E 's/(TAG|TAA|TGA)$//'

Or this sed without extended regex (doesn't work on OSX though):

sed 's/\(TAG\|TAA\|TGA\)$//'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

the use of "+" in sed regular expression

From Dev

sed regular expression failure

From Dev

the use of "+" in sed regular expression

From Dev

Regular expression with sed

From Dev

sed regular expression extraction

From Dev

sed command with regular expression

From Dev

Negation of sed regular expression

From Dev

Sed Regular Expression with /P

From Dev

+ Regular Expression not working in sed

From Java

Escaping plus in sed regular expression

From Dev

sed positional replacement with regular expression

From Dev

Sed multiline regular expression issue

From Dev

understand Regular expression in a sed command

From Dev

sed regular expression failed on solaris

From Dev

sed: regular expression,how to substitute?

From Dev

sed replace regular expression match

From Dev

Using Sed in a for loop with a regular expression

From Dev

sed regular expression for escaped urls

From Dev

How to match everything but a regular expression with sed?

From Dev

Converting a sed regular expression to python code

From Java

regular expression in sed replace question mark

From Dev

Is there another regular-expression "flavor" in GNU sed?

From Dev

sed to edit only part of a file with regular expression

From Dev

Converting a sed regular expression to python code

From Dev

Using Sed with regular expression to save results into a variable

From Dev

How to use [\w]+ in regular expression in sed?

From Dev

sed regular expression matching more than intended

From Dev

How to match everything but a regular expression with sed?

From Dev

sed: how to insert a newline into a regular expression?