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.
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.
.
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
.
Essentially, this command removes everything from the first dash ('-') up to the end of the input.
$ is the end of line regex so it reads a line with a - followed by anything on the line.
.
is any character.*
is "zero or more times"Thus, .*
is "any character, zero or more times"