views:

39

answers:

2

I have the following text file

Eif2ak1.aSep07
Eif2ak1.aSep07
LOC100042862.aSep07-unspliced
NADH5_C.0.aSep07-unspliced
LOC100042862.aSep07-unspliced
NADH5_C.0.aSep07-unspliced

What I want to do is to remove all the text starting from period (.) to the end. But why this command doesn't do it?

sed 's/\.*//g' myfile.txt

What's the right way to do it?

+3  A: 

You're missing a period there. You want:

s/\..*$//g
Clint Tseng
You've escaped the period to make it a literal. To match the rest of the line, you'll need another matching pattern, like '.*' or better yet '.*$'. That makes your expression look like Clint's
Andrew B
+1  A: 

you can use awk or cut, since dots are your delimters.

$4 awk -F"." '{print $1}' file
Eif2ak1
Eif2ak1
LOC100042862
NADH5_C
LOC100042862
NADH5_C

$ cut -d"." -f1 file
Eif2ak1
Eif2ak1
LOC100042862
NADH5_C
LOC100042862
NADH5_C

easier than using regular expression.

ghostdog74