Quickest Way to Create Text File of Specific Length
In order to perform a specific test of my new application SetACL Studio I needed a string with a length of exactly 32,739 bytes.
How to Create Such a Beast
That was the question I asked myself. I was not thrilled by the prospect of copying and pasting blocks of text in an editor until the required length had been reached.
Luckily I remembered that Perl has a function that makes such a task trivial: the ‘x’ operator. Here is what I came up with:
perl -e "print '1' x 32739" > 32739.txt
If you have Perl installed, that line can be executed from the regular Windows command line. “Perl -e” executes one command string (enclosed in double quotes). The result is then written to the file 32739.txt with the command line’s output redirection operator “>”.
Are there any other elegant ways to create a text file with one line of exactly 32,739 characters? If you know of one, please let me know by commenting below.