Server Fault is a question and answer site for system and network administrators. 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

I need to print text between two text fragments. I've found such example, that does exactly what I want, but I don't understand how it's done. Googling is difficult because command does not contain letters)

sed -n '/hostname/,/$/p' /tmp/ambari-agent.ini


As I understand, here I print text between hostname and line end. p option prints pattern to output. But why do I have three groups here and what does coma mean here?

share|improve this question
Thank you, Zoredache. I've found the complete doc here – Dmitriusan Apr 2 '13 at 17:59
up vote 3 down vote accepted

Almost always the first place you should look is the man pages. They are often difficult to read, but the information is there.

From the man page p Print the current pattern space., it is in the subsection Commands which accept address ranges. Which would easily lead you to the idea that you are specifying a start and end address range by using regular expressions, see the Addresses section. So /hostname/ is the start and /$/ is the end. The $ is a special character that marks the end of a line.

share|improve this answer
Thanks for reply – Dmitriusan Apr 2 '13 at 18:22

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.