NAME
LimitLineLengthInFile — Take file and run textutil::adjust::adjust on each line.
SYNOPSIS
LimitLineLengthInFile MaxLength InputFilePath ?OutputFilePath?
DESCRIPTION
Return Value
None.
Arguments
MaxLengthMaximum length that any line in the file can have.
InFilePathPath of the file to read.
OutFilePathOptional. Path of the file to write. By default, this command will read and write the same file.
More Info
For any lines with leading whitespace, this command will preserve that whitespace.

This command is really for files that have not had their line length previously limited. It is not for files that have paragraphs broken across lines based on a certain width and now you want to change that width.

For instance, it is more for this:

     Here is the start of a paragraph. This paragraph is continuing on one line for over 80 characters, but will be split over several lines, with newlines, once we run the command.

Here is another paragraph that is also all on one line in the source file. This will also be broken up and we end with two paragraphs.

than for this:
Here is another paragraph,
which has been limited to
xxx characters in width
already.

See also: ::textutil::adjust, especially if you find that this command will not give you the exact results you are looking for.

Note that this command uses the -length $MaxLength and -strictlength true options of ::textutil::adjust::adjust. The result may be slightly off from what you would expect, but we decided not to make any adjustments. Specifically, if you specify a MaxLength of 80 and one of the lines has 81 characters with no whitespace, then it will have 81 characters in the output. But so long as the line has at least one whitespace then it will be 80 or less. The examples and tests make this more clear.

It is recommended that you try this out on some files and see if you get results you like. If not, and you know just what you want, it may be well to use a more sophisticated (and more complex) tool.


For information regarding exceptions / errors, see here.
EXAMPLES
% set Lines {333 4444 55555 666666}
% List2File $Lines temp.txt
% LimitLineLengthInFile 4 temp.txt
% cat temp.txt
333
4444
55555

66666
6
% set Lines {333 4444 { 5 55} {   6 66}}
% List2File $Lines temp.txt
% LimitLineLengthInFile 4 temp.txt
% puts [File2String temp.txt]
333
4444
5
55
6
66

KEYWORDS
file, format, string