Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Mar 7 '12 at 14:26

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

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

4 Answers

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

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

share|improve this answer
add comment

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

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

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.