print out certain line numbers with sed.

It has been a year now since I completed my UNIX/Linux certification training and every once and awhile I think about my friend Perl, but I really enjoy helping others with some simple needs. Ben (yeah, I got him using WordPress too ;)) aked me a great recently:

Question: If i have a huge log text fie and i want to pull a range of lines out of the middle, how can I easily do this?

Answer: sed -n '3,6 p' /var/log/httpd/error_log

Answer broken down:

  • sed is the UNIX tool I chose for this.
  • -n is used so that sed does not print out more than what I need.
  • '3,6 p'indicates that I want lines 3-6 of the log file to print out (in the command line) and the p is used for: “If the substitution was made, then print the new pattern space.”
  • /var/log/httpd/error_log specifies the log file that I need to extract data from

Hope this comes in handy!
[tags] sed [/tags]

About the Author...

Jennifer Zelazny

My name is Jennifer Zelazny and this site is a collection of my random thoughts and opinions. I am Penn Stater, WordPress developer, and a modern day explorer. I love exploring data, trends, and things that make the world a better place and sharing them here.

Leave a Reply

Your email address will not be published.
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.