You have been reading shell programming tutorials (and possibly C shell, if they advice round parentheses in the
if -- that's different from Bourne shell, sort of like Java is quite unlike JavaScript, although not quite as unrelated) but the program you have written is in the
awk language, which is not at all the same thing. Compare to how you can use a DLL written in another language from a C program. But with scripts, the source can be in two different languages, and often is -- you frequently put small
awk or
sed or
Perl or
TCL or ... other scripts in shell scripts where the shell's own syntax or facilities don't match the problem space well enough.
The
Perl program does what I imagine your spec says it should do. Try it and see. It replaces multiples of 119 charactes or less followed by a space or a comma with the same string plus a backslash and a newline. You could do the same in
sed or
awk, albeit not quite as succinctly; the main concept here is a
regular expression, which is a facility all of these languages provide. (I think you have it in VB, too, and there are C libraries you can link to if you like.) Read up on that, it's an extremely useful and versatile tool, quite independent of any particular language.