print out certain line numbers with sed.

Hints HOWTOs UNIX

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]

Leave a Reply

Your email address will not be published.
*
*

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

Videos

Video Blogs

Yeah, I am late to post about video blogs, but hopefully this will be news for some ;). I have been watching Rocketboom for a little over a month now and love it (today it went high def!). Not only do I watch it…my TiVo downloads it and has it ready for me every night […]

Web Development

Real Artists Ship

The perfectionist in me wants to wait to introduce a new design, etc until everything is perfectly in place. But recently, I was reminded that “real artists ship“. I am starting to get more consulting business and I was unhappy with my business web site design. It was dark, uninviting, and just felt heavy. I […]