AWK limit for (length) function?

I am trying to use the following code:

awk '{s=$0;if(length(s) < 750){getline; s=s " " $0}printf("%s\n",s)}' filename

but an error shows that 'awk' is too long. Is there a limit to the awk length function? and what could be an alternate solution for long fixed width records?

The code removes a \n (new line feed) within a record without removing the record delimter.

Thanks!

Yes, awk has limitation on the number of chactacters of 3000 characters or something which is the maximum input record size.
However gawk and mawk doesn't seem to have such limits. It can hold upto the max value of C long

So try using gawk instead of awk

gawk '{s=$0;if(length(s) < 750){getline; s=s " " $0}printf("%s\n",s)}' filename

cheers,
Devaraj Takhellambam

Another way:

nawk 'length($0) < 750 {s=$0;getline;print s, $0}' file

An alternate solution for long records could be perl. Unlike *awk, it does not impose any limitation on size of input records. You are only limited by the memory in your system.

$
$ cat input.txt
12345abcdeMy
name
is
Jack SmitSVY01
23456fghijMy name is
John SmitSVY02
34567klmnoMy name is Cole SmitSVY03
45678pqrstMy name is
Dave
SmitSVY04
56789uvwxyMy name is Eric
SmitSVY05
$
$ perl -ne '{
>   if (length($_) < 36) {chomp; $buf=$buf." ".$_;
>     if (length($buf) == 36) {print substr($buf,1),"\n"; $buf="";}}
>   else {print}
> }' input.txt
12345abcdeMy name is Jack SmitSVY01
23456fghijMy name is John SmitSVY02
34567klmnoMy name is Cole SmitSVY03
45678pqrstMy name is Dave SmitSVY04
56789uvwxyMy name is Eric SmitSVY05
$
$

tyler_durden