Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Are there any better solution to this?

tail -200 /var/log/messages | head -100

Are there other methods to achieve this output? (not more complex, I'm looking for simpler solutions!)

share|improve this question
    
just wondering, why would you want to look at the lines 200 to lines 100 (from the bottom) and not the last 100 lines, or is the intention to check 100 lines at a time? –  freethinker May 20 '11 at 7:16
1  
This is simple enough as it is. If that is a small part of a bigger task, you may need to describe and ask about that. –  forcefsck May 20 '11 at 7:33
    
actually firstly I used tail -1000 so I read the last 1000 lines, but I needed more to read, and I don't wanted to scroll the last 1000 –  LanceBaynes May 20 '11 at 7:47
add comment

2 Answers

up vote 2 down vote accepted

If you want to browse through a file interactively, just use less log. You can exit less via q, h is the help screen. Example session:

:G
:1000k
:100
:f
:b

(which means: jump to the end, move 1000 lines up, 100 lines down, one screen forward and one screen backward)

share|improve this answer
    
I'd also recommend view, if you are familiar with vi. –  jmtd May 20 '11 at 12:31
add comment

If you know the starting line number (counted from the beginning of the file), you can use sed like this to output the above lines intervall:

$ for i in `seq 500`; do echo $i; done > t
$ sed -n '300,400p' t
300
...
400

(which prints the lines 300 until 400)

If you don't know the start line (address in sed lingo), you can reverse the input, use sed and reverese again:

$ tac t | sed -n '101,201p' | tac
300
...
400

You can also use sed with a start address and specify how many following lines should be printed:

$ tac t | sed -n '101,+100p' | tac
300
...
400
share|improve this answer
add comment

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.