sed: unterminated address regex
I have a simple problem.
I basically want a regex that will exclude everything after the last dot in my hostname: V677.Centauri.net to V677 which I was going to use the following: Code:
/\.[^]*$/ Code:
sed '/\.[^]*$/p' /etc/HOSTNAME Code:
sed: -e expression #1, char 9: unterminated address regex How do I terminate the address? Or what else should I do to allow the command to run? |
the ^ has special meaning inside [] that is not used properly. From the other hand what was the goal of it: [^]?
what is that p at the end of the regexp? |
Thats a sed operator. There are two associated w/ regex's:
- p: print - d: delete .. and I believe s which subtitutes. I could use a perl one liner which I will most likely do, but I would also like to get this down because I know sed is simpler and ready to employ in certain cases/ stripped down systems. Quote:
|
sed 's/\..*//' will do that I think. Sed automatically prints, so p is not required....
|
Quote:
Code:
/\.[^.]*$/ |
Quote:
There is no way to write a bracket expression with an empty list (Why would anyone want to do that?), nor can a bracket expression contain just a single literal ^ character (must be placed anywhere but first in the list). And as pan64 asked, what was the intent of that "[^]*" anyway? I read that as intended to mean, "any number of characters that are not nothing," better expressed as ".*". |
You know, I apologize. It was late, and when I read your reply pan, I did not see that you were asking the purpose of the [^] expression.
Quite honestly, I have a basic understanding of regular expressions. I tested the expression at the following site: http://www.regexr.com/ .. and it gave me the result I was looking for. So, to answer your question folks, I couldn't answer other than that is what made the expression give me the results I wanted. I'll test this momentarily. |
that site cannot evaluate properly this expression: [^] (which is syntactically incorrect, but that site accepts)
http://www.myezapp.com/apps/dev/regexp/show.ws |
Quote:
Quote:
|
Pan, I was reading over this again and I have to say, the latter solution is simple and I like it! Thanks for sharing :)
|
All times are GMT -5. The time now is 12:15 AM. |