1

Possible Duplicate:
Linux text editor for working with huge files

I have a log file with more 200,000 lines. How can i see the lines from 4500 to 5000. I am not sure vi editor opens up such a huge file. Please help

Community
  • 1
  • 1
Jayy
  • 2,368
  • 4
  • 24
  • 35
  • If you have the ram on your PC, it should open it up fine. Otherwise, you can make a little Perl/Python/C app that you pipe the file into along with a range of lines you'd like to output. If you're lazy and the lines are numbered, just use the "more" command and hold space bar for a while :p – John Humphreys Oct 11 '12 at 21:32

2 Answers2

3

vi can open such files. That's the reason that makes vi such an amazing editor. But you can display your file with head -n 5000 hugefile.txt | tail -n 500

tomahh
  • 13,441
  • 3
  • 49
  • 70
  • oh ok, i didnt know. i think the combination of head and tail command is also a good one – Jayy Oct 11 '12 at 15:18
  • Kent solution is a better one. Sed may not open the whole 5000 line to output only 500 of those. – tomahh Oct 11 '12 at 15:19
  • which one is a better in terms of cpu usage b/w vi editor and head|tail? any idea. i dont want my command that takes all the cpu – Jayy Oct 11 '12 at 15:20
  • For 5000 lines, neither of the both will over-use the CPU. But Kent solution's is the better one. – tomahh Oct 11 '12 at 15:21
  • the head | tail one should not work. head -n 4500 gives the first 4500 lines, and tail -n 5000 gives the last 5000 lines from input. in your command, the result would be 1-4500 lines. but OP wants 4500-5000 lines. am I right? – Kent Oct 11 '12 at 15:22
  • @Kent That's why i edited my answer 4 minutes ago ;D This now works. But as I said, your solution is the better one. – tomahh Oct 11 '12 at 15:25
  • thx. just noticed your edit.. – Kent Oct 11 '12 at 15:27
3
sed -n '4500,5000{p}' log.file

then you can either pipe it to less or > to a new file.

Kent
  • 189,393
  • 32
  • 233
  • 301