vi: Line too long
Asked Answered
C

2

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?
Compression answered 5/9, 2012 at 7:15 Comment(0)
L
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.

Lorsung answered 5/9, 2012 at 7:18 Comment(7)
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 repeatedNormandnormandy
@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.Lorsung
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 :)Normandnormandy
@Lorsung Thanx so far. Well problem is that vim is not installed.Compression
@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 ... :-)Lorsung
@Lorsung 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.Compression
@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.Lorsung
N
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
Normandnormandy answered 5/9, 2012 at 7:19 Comment(3)
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.Lorsung
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.Normandnormandy
Thats what helped as a workaraound. Where I used fold -2048 your_file > your_file_foldedCompression
L
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.

Lorsung answered 5/9, 2012 at 7:18 Comment(7)
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 repeatedNormandnormandy
@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.Lorsung
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 :)Normandnormandy
@Lorsung Thanx so far. Well problem is that vim is not installed.Compression
@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 ... :-)Lorsung
@Lorsung 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.Compression
@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.Lorsung

© 2022 - 2024 — McMap. All rights reserved.