VI command "line too long"

Hello, I had posted this initially in the UNIX for dummies forum which is now locked to new posts. I have a machine running IRIX and I need to edit a text file on the terminal but I get a "line too long" error when using the vi command. The text file in question is tens of thousands in lines so I'm not sure if that is related to it. User bakunin suggested the sed command but I get similar results. Can someone show me step by step on a possible workaround with this since I'm a bit rusty on this stuff? Thanks in advance!

James

By definition, text files meet all of the following requirements:

  1. the file does not contain any NUL characters,
  2. every line in the file is terminated by a <newline> character, and
  3. no line in the file (including the terminating <newline> character) contains more than LINE_MAX bytes.

On many systems, LINE_MAX is 2048. The value on your system can be determined using the command:

getconf LINE_MAX

The message you are getting probably indicates that the file you are trying to edit is not a text file because it violates requirement #3 in the list above.

If you want to split long lines in a file into shorter, adjacent lines that meet the requirements of a text file, try using the fold utility. If you want to split long lines into segmented files where one file contains the 1st X characters from each line from an input file and another file contains the X+1st through the 2Xth character from each line from an input file, etc.; try using the cut utility.

Without knowing more about the format and contents of the file you are trying to edit and the changes you want to make to that file, it is hard to suggest anything more specific.

3 Likes

Hi Don thanks for your reply. The files I'm trying to view are .dat files. The maximum number of lines is 2048 like you suggested. I don't believe there are any <newline> tags located within the contents of the files.

'newline' is a single ascii character, ASCII 10, usually written by us humans and sometimes UNIX utilities as \n

It is not the number of lines in the file, LINE_MAX refers to line length. The longest allowed length of any one line in the file. Or. The maximum number of bytes allowed in a line. Further, lines are defined as having the newline character (\n) at the end of the line.

Files that have a logical structure but no \n characters, or files with lines that do have carriage control (\n exists) but with lines > 2048 bytes will get this error.

So are you saying there is no way around this (i.e. I can't increase the limit)? The file I'm trying to edit is a .dat data file for a program so I don't want to make new lines and potentially break something.

You say above that you have a text file; but we have showed you the definition of a text file and your .dat file(s) do NOT meet the definition of a text file. You say above that your text file has thousands of lines, but in post #3 in this thread you say that there are no <newline> characters. So by definition, your .dat file doesn't contain any lines.

Why do you say that you have thousands of lines in a file if there are no <newline> characters and you know that every line in a file is terminated by a <newline> character?

We can't help you if you don't explain the format of the data in your .dat file(s) and explain what change(s) you hope to make to your .dat file(s)

Haven't done it with Unix tools but did it with basic under MSDOS, reading character by character from the .dat file, writing to a new .txt file character by character and converting a delimiter to a line break at the correct place.

(Apologies for any typos.)

Not sure which MS-DOS BASIC you are using, I guess QBASIC, as BASICA is so old as to be buried. GWBASIC and ASIC spring to mind too.

(Are you trying to list a QBASIC.EXE interpreter script/program in a UNIX environment?
If so IIRC these scripts were saved in Tokenised format for the BASIC statements which effecively makes the file binary. If not ignore this paragraph.)

However it looks like your ".dat" file contains binary, if so and you are in a *NIX like shell give us a short dump of, (this command exists in CygWin if you using that environment):-

od -tx1 -c < [/full/path/to/]your_file.dat