Quickest Way to Create Text File of Specific Length

  • Scripting
  • Published Aug 21, 2011 Updated Sep 6, 2011

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.

Perl

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 “>”.

Alternatives?

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.

Comments

Related Posts

Blocking Office Macros, Managing Windows & macOS via Intune

Blocking Office Macros, Managing Windows & macOS via Intune
How to centrally manage essential security settings of self-managed devices This is a guest post by Martin Kretzschmar, customer success engineer at vast limits, the uberAgent company. One thing I especially like about my everyday working life is the flexibility it offers. I appreciate the freedom of choice in terms of location, time and device. We want to avoid getting into micro-management but, being an IT company, we also need to provide the necessary security where needed.
Scripting

Latest Posts