Reputation: 522
I have a list of DNS name of my ELB's and I want to extract the load balancer name from the DNS name.
Lets say if the DNS name is my-example-loadbalancer-123456789.us-east-1.elb.amazonaws.com, I would like to extract the name my-example-loadbalancer .
Upvotes: 0
Views: 350
Reputation: 4979
The problem is to find a pattern that matches the part that you want to keep or the part that you want to remove. In the case of your question and comments, it seems that you could use
sed 's/-[0-9]\+.*//'
You could match the extra . explicitly, as Michael-sqlbot suggested. You could also add more of the names that is identical, for example:
s/-[0-9]\+.us.*//
(or s/-[0-9]\+\.us.*//
if you want to match the . explicitly). The point is that you will need to look at how your data is structured in the way of possibilities. If you have non-US loadbalancers, for example, you probably won't try to match the us
.
Upvotes: 1