views:

63

answers:

3

I have a data that looks like this:

AB208804_1 446 576 AB208804_1orf 0
AB208804_20 446 576 AB208804_20orf 0

I want to convert them into this:

AB208804 446 576 AB208804orf 0
AB208804 446 576 AB208804orf 0

just by removing _\digit part in column 1 and 4.

Why this line doesn't work:

sed 's/_\d+//g'

What's the correct way to do it?

+2  A: 

Try:

sed 's/_[0-9]\+//g' 
codaddict
+4  A: 

You need the -r switch and a character class for the sed.

$ echo "AB208804_1 446 576 AB208804_1orf 0" | sed -r 's/_[0-9]+//g'
AB208804 446 576 AB208804orf 0

Or, since you asked; in perl:

$ echo "AB208804_1 446 576 AB208804_1orf 0" | perl -ne 's/_\d+//g; print $_'
AB208804 446 576 AB208804orf 0
zen
ITYM `perl -pe 's/_\d+//g'` :)
hobbs
TY hobbs. I'd gotten -p and -i confused, even though it's easy as 'pie'. ;)
zen
+1  A: 
 sed 's/_[0-9][0-9]*//g' file
ghostdog74