Discussion Locked

Nawk problem - input string too long

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,

I was wondering if one of you have the answer to the following problem :

I am using an (n)awk script on SCO Unix to read in variables from an input file, and output them in a particular order.
However, when I outut my long line of data, there is some junk tagged onto the end (looks like one of the earlier variables).
I tried running the script through with the output print line commented out (to see if it still print the rougue data) and I got the following error message -
"Input string too long, limit 200"

I guess that this could have something to do with the rougue data apearing at the end of my print output(?)

Any ideas?

5 replies

by cavedweller

Is your input line really that long? Are you trying to read a text file with "odd" end of line termination like a DOS file ftp'd in binary mode? If this is the case, in the BEGIN section specify the EOL character instead of using the default. Another option would be to use sed to pre-process the file and change the EOL.

If the problem is that your output line is too long after putting all the fields together, just print it out in multiple pieces. If you don't add the EOL to a printf, thenext printf appears on the same line as the previous. Add the EOL after the last chunk has been output.

by cavedweller

I read your question again. Junk that looks like previous lines at the end of your line? This sounds like an uninitialized buffer.
Are you reading in a line and then trying to use the data words individually? Let's suppose, for example, you read in a line and try to manipulate up to 10 elements (words) and then output them. If there were 10 elements on a line and you tried to print out 1-10 in sequence you would see the correct results. If on the next line there were only 8 input elements, your output would contain the current lines 1-8 and the previous line's 9-10. (Since 9 and 10 weren't overwritten by the read they retain their previous value).
Testing the NF variable (Number of Fields) is usually the best method. Instead oflooping from 1 to 10 you should loop from 1 to NF. Another alternative is to clear all the buffers before reading the next line.

This might be a related issue. If your input fields run together, nawk might not split up the imput the way you expect. If the input file was written with fixed width columns and one of the columns is filled to the maximum width (no white space between it and the previous column) nawk would count both columns as the same field.

Hope this helps.

by bmw

Good ideas.
I have just checked the line length of my input file ( cat | awk '{print length($0)'| sort -k1n ), and it goes up to a max of 197 characters wide on some lines.
Each line of my input file is terminated with a carriage return (^M) - so I guess that should be ok.
I don't think that it's a problem with my output line length, as, even though it is long (a few hundred chars) - this error message only appears when I 'don't' output any print lines (I commented the print line out) so there is no printed output other than the error message.
Anything else you can think of?
Cheers.

This discussion is closed to new replies.