Reputation: 9978
How can I use sed
to delete all the chars from the last dot on?
e.g.:
ns:base.cocktails.cocktail_garnish
ns:user.maport.cocktail.cocktail_recipe
ns:base.cocktails.cocktail_drinkware
ns:user.pjf.default_domain.chicken_breed
ns:user.radiusrs.default_domain.astrological_sign
ns:base.disaster2.type_of_tornado
I want to get:
ns:base.cocktails
ns:user.maport
ns:base.cocktails
ns:user.pjf.default_domain
ns:user.radiusrs.default_domain
ns:base.disaster2
Upvotes: 0
Views: 61
Reputation: 58508
This might work for you (GNU sed):
sed 's/\(.*\)\..*/\1/' file
Used greed to find the last .
and delete thereafter.
Upvotes: 0
Reputation: 41460
You could use awk
awk 'BEGIN {OFS=FS="."} NF--' file
But sed
is better for this job.
Using the sed
regex:
awk '{sub(/\.[^.]*$/,"")}1' file
Upvotes: 1