简体   繁体   中英

Replacing Part of Text Using Sed

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?

You're missing a period there. You want:

s/\..*$//g

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM