2

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?

3

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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