1

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.

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

4 Answers 4

9

. 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.

1

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

0

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

0
  • . is any character.
  • * is "zero or more times"

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

You must log in to answer this question.