7

When I use vi to analyze log files, it sometimes is stuck with the error: 'Line too long'. I can watch the file using more, but that's not what I want.

The command view leads to the same result and less is not installed.

System is HP-UX v B.11.31 U ia64

  1. What does this error mean? Does vi really have a limitation on how many characters per line is allowed?
  2. Is there a workaround how to get the files open and displayed in vi anyway?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

2 Answers2

7

Find out the limit supported, then use fold

fold -80 your_file | more

Or

fold -80 your_file > /tmp/your_file.0
vim /tmp/your_file.0
sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    Folding lines is likely to make analysis much harder since the information is now on _multiple_ lines - you're better off leaving the file alone and choosing a better analytics tool. – paxdiablo Sep 05 '12 at 07:27
  • 1
    Yeah, I never have this issue, but I use vim :) Just throwing it out there; quite probably the OP isn't aware of this tool. – sehe Sep 05 '12 at 07:57
  • Thats what helped as a workaraound. Where I used _fold -2048 your_file > your_file_folded_ – Nicolas Schwarzentrub Sep 05 '12 at 08:20
2

(1) Apparently so :-)

I've never run into a limitation in vim (a) before but it may be that the vi shipping with HPUX is not vim.

(2) What sort of analysis are you doing on log files with vi?

This is the sort of task perfectly suited to text processing tools like sed, awk and Perl, in order of increasing awesomeness.


(a): You may want to consider grabbing vim if you don't have it already. From the vi_diff part of the documentation (differences between vi and vim):

Vim has only a few limits for the files that can be edited {Vi: can not handle characters and characters above 128, has limited line length, many other limits}.

Maximum line length: On machines with 16-bit ints (Amiga and MS-DOS real mode): 32767, otherwise 2147483647 characters. Longer lines are split.

Maximum number of lines: 2147483647 lines.

Maximum file size: 2147483647 bytes (2 Gbyte) when a long integer is 32 bits. Much more for 64 bit longs. Also limited by available disk space for the swap-file.

Community
  • 1
  • 1
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • In what way does this answer the question? FWIW, I vastly prefer using vim for this kind of job, unless it is going to be repeated – sehe Sep 05 '12 at 07:20
  • 1
    @sehe, I believe it was answered by the bit that said `vi` wasn't really suitable for the job of log file analytics. I've also added the bit at the end that says, if you _must_ use `vi`, get your hands on `vim` instead which has much higher line lengths. – paxdiablo Sep 05 '12 at 07:25
  • the added information on length limits make this more apparent now. At first your answer to "Does anybody know a workaround how to get the files open and displayed in vi anyway?" was basically: use sed, awk, perl :) – sehe Sep 05 '12 at 07:56
  • @paxdiablo Thanx so far. Well problem is that vim is not installed. – Nicolas Schwarzentrub Sep 05 '12 at 08:24
  • @NicolasSchwarzentrub, solution therefore is to install vim :-) But seriously, I would consider the scripting languages a better way to go. They will really give you a lot more expressive power to manipulate logs. Vi is a _very_ powerful editor but it's not your swiss army chainsaw for everything - emacs, on the other hand ... :-) – paxdiablo Sep 05 '12 at 08:28
  • 1
    @paxdiablo and how do you install vim, if you don't have the rights to :-( ? Otherwise I agree with you. But if you don't have the time to learn new tools, you take tools you already know. – Nicolas Schwarzentrub Sep 05 '12 at 08:39
  • @NicolasSchwarzentrub, well, it's either your machine (unlikely for HPUX) or a work one. If it's a work one, you probably have processes in place to install software. Otherwise, vim is quite capable of being built from source so you could make your own local copy. And you're right: use the tools you know first. But _not_ if they're inadequate to the task you want to do. – paxdiablo Sep 05 '12 at 08:42