Duplicate Rows in Text File
I Need to Duplicate Rows in Text File with a Specific Number of Times. for Example My Data File Is: Jplg3350.18I Jplg3360.18I Jplg3370.18I I Need to Duplicate...
I need to duplicate rows in text file with a specific number of times. For example my data file is:
jplg3350.18i
jplg3360.18i
jplg3370.18i
I need to duplicate the lines three times as follows;
jplg3350.18i
jplg3360.18i
jplg3370.18i
jplg3350.18i
jplg3360.18i
jplg3370.18i
jplg3350.18i
jplg3360.18i
jplg3370.18i
1 Answer
For 3 times you can just run:
cat file file file > new_file
And here is a trick if you're lazy like me and you don't want to re-type the file name N times. Type cat then the filename, Press Ctrl+W, then Ctrl+YSpace N times, finally type > new_file.
However it's a better idea to use a simple "loop" in combination with cat command.
3 times example:
for i in {1..3}; do cat file >> new_file; done
Or as you asked in comments:
limit=3
for ((i=0; i<limit; i++)); do cat file >> new_file; done
Change '3' to any number you want.
Result:
jplg3350.18i
jplg3360.18i
jplg3370.18i
jplg3350.18i
jplg3360.18i
jplg3370.18i
jplg3350.18i
jplg3360.18i
jplg3370.18i