Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

hostname=localhost

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
    
See: stackoverflow.com/questions/13242469/… –  Zoredache Apr 2 '13 at 17:56
    
Thank you, Zoredache. I've found the complete doc here grymoire.com/Unix/Sed.html#uh-29 –  Dmitriusan Apr 2 '13 at 17:59

1 Answer 1

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

 
discard

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.