How to create a large text-based file from repeating the contents of an exist file

I need to be able to create a very large text file from a small existing file. It needs to be as small as 1 MB and as big as 5 MB. Below is the initial starting file content.

I am told one can use "dd" command or "fallocate", but I don’t see a way to use these by growing an existing file. I would grateful for any ideas. Thanks

Delivered-To: user1@company1.com
From: no-reply@accounts1.something.com
To: somedude@something.com

Delivered-To: user2@company1.com
From: no-reply@accounts.something.com
To: somedude@something.com

Delivered-To: user3@company1.com
From: no-reply@accounts.something.com

>Solution :

You can use cat to concatenate the file multiple times.

cat file.txt file.txt file.txt > newfile.txt

will repeat the contents 3 times. If you want to make it dynamic, use a loop that appends.

numcopies=100
> newfile.txt
for ((i = 0; i < numcopies; i++)); do
    cat file.txt >>newfile.txt
done

Leave a Reply