Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What does the -.*$/ in this command mean? Please help me decipher this.

echo -n full | sed -e "s/-.*$//" 

I know what sed does and all that, I just want to know what this -.*$ part is.

share|improve this question

migrated from Mar 7 '12 at 14:26

This question came from our site for professional and enthusiast programmers.

Dash, followed by the rest of the line. Did you look at any documentation before coming here? – Beta Mar 7 '12 at 14:21

. stands for any character, * means to match any amount (between 0 and infinite) of the previous match and $ stands for end of line. So this sed command will match - followed by all characters after it until it find the end of the line and replace that with nothing, i.e. delete it.

So for example: aajaaa-woijsdfljkwe94 becomes aajaaa

Also, it should be noted that * is 'greedy', which means it will match as many characters as possible. So, for example: alasdf-slwddo-sdf becomes alasdf, not alasdf-slwddo.

share|improve this answer

Essentially, this command removes everything from the first dash ('-') up to the end of the input.

share|improve this answer

$ is the end of line regex so it reads a line with a - followed by anything on the line.

share|improve this answer
  • . is any character.
  • * is "zero or more times"

Thus, .* is "any character, zero or more times"

share|improve this answer

You must log in to answer this question.