Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading