Guillermo Espert
Guillermo Espert

Reputation: 1310

How to generate a 10000 lines test file from original file with 10 lines?

I want to test an application with a file containing 10000 lines of records (plus header and footer lines). I have a test file with 10 lines now, so I want to duplicate these line 1000 times. I don't want to create a C# code in my app to generate that file (is only for test), so I am looking for a different and simple way to do that.

What kind of tool can I use to do that? CMD? Visual Studio/VS Code extension? Any thought?

Upvotes: 1

Views: 255

Answers (1)

collapsar
collapsar

Reputation: 17258

If your data is textual, load the 10 records from your test file into an editor. Select all, copy, insert at the end of file. Repeat until the file is of length 10000+

This procedure requires ceil(log_2(1000)) cycles, 10 in your case, in general ceil(log_2(<target_number_of_lines>/<base_number_of_lines>)).

Alternative (large files)

Modern editors should not have performance problems here. However, the principle can be applied using a cat cli command. Assuming that you copy the original file into a file named dup0.txt proceed as follows:

cat dup0.txt dup0.txt >dup1.txt
cat dup1.txt dup1.txt >dup0.txt

leaving you with the quadrupled number of lines in dup0.txt.

Upvotes: 0

Related Questions