Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with sed

Status
Not open for further replies.

cstorm

MIS
Oct 1, 2001
69
US
I need to print all lines between a certain pattern.
Example, filea contains:

start server1.d35.acme.com
text message 1
text message 2
end server1.d35.acme.com
start server9.d35.acme.com
text message 1
text message 2
end server9.d35.acme.com
start server10.d35.acme.com
text message 1
text message 2
end server10.d35.acme.com

I want only the text pertaining to server1. I have tried
the command:

sed -n '/server1/,/server1/p' filea

But, it produces text for server1 and server10:

start server1.d35.acme.com
text message 1
text message 2
end server1.d35.acme.com
start server10.d35.acme.com
text message 1
text message 2
end server10.d35.acme.com

What is the solution?

 
Try

sed -n '/server1\./,/server1\./p' filea

If server1 can be followed by characters other than a period, comma and colon for example, use

sed -n '/server1[.,:]/,/server1[.,:]/p' filea



CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Wow! Case solved. Thanks to CaKiwi for the speedy solution!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top