Duplicate rows in text file












3















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









share|improve this question

























  • See also superuser.com/q/338616/418028

    – Sergiy Kolodyazhnyy
    Jan 7 at 14:13
















3















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









share|improve this question

























  • See also superuser.com/q/338616/418028

    – Sergiy Kolodyazhnyy
    Jan 7 at 14:13














3












3








3








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









share|improve this question
















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






bash text-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 7 at 14:09









Kulfy

4,05351241




4,05351241










asked Jan 7 at 10:41









deepblue_86deepblue_86

5781023




5781023













  • See also superuser.com/q/338616/418028

    – Sergiy Kolodyazhnyy
    Jan 7 at 14:13



















  • See also superuser.com/q/338616/418028

    – Sergiy Kolodyazhnyy
    Jan 7 at 14:13

















See also superuser.com/q/338616/418028

– Sergiy Kolodyazhnyy
Jan 7 at 14:13





See also superuser.com/q/338616/418028

– Sergiy Kolodyazhnyy
Jan 7 at 14:13










1 Answer
1






active

oldest

votes


















10














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





share|improve this answer





















  • 2





    You couldn't even let the little guys take this one! Happy New Year Rav!

    – George Udosen
    Jan 7 at 10:53













  • :)) Happy to you too George ;)

    – Ravexina
    Jan 7 at 10:54













  • @George, thank you very much.

    – deepblue_86
    Jan 7 at 11:07






  • 1





    Another lazy trick is to use brace expansion with an empty string: cat file{,,} > new_file

    – wjandrea
    Jan 7 at 14:17











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1107686%2fduplicate-rows-in-text-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









10














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





share|improve this answer





















  • 2





    You couldn't even let the little guys take this one! Happy New Year Rav!

    – George Udosen
    Jan 7 at 10:53













  • :)) Happy to you too George ;)

    – Ravexina
    Jan 7 at 10:54













  • @George, thank you very much.

    – deepblue_86
    Jan 7 at 11:07






  • 1





    Another lazy trick is to use brace expansion with an empty string: cat file{,,} > new_file

    – wjandrea
    Jan 7 at 14:17
















10














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





share|improve this answer





















  • 2





    You couldn't even let the little guys take this one! Happy New Year Rav!

    – George Udosen
    Jan 7 at 10:53













  • :)) Happy to you too George ;)

    – Ravexina
    Jan 7 at 10:54













  • @George, thank you very much.

    – deepblue_86
    Jan 7 at 11:07






  • 1





    Another lazy trick is to use brace expansion with an empty string: cat file{,,} > new_file

    – wjandrea
    Jan 7 at 14:17














10












10








10







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





share|improve this 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






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 7 at 11:00

























answered Jan 7 at 10:46









RavexinaRavexina

31.8k1482112




31.8k1482112








  • 2





    You couldn't even let the little guys take this one! Happy New Year Rav!

    – George Udosen
    Jan 7 at 10:53













  • :)) Happy to you too George ;)

    – Ravexina
    Jan 7 at 10:54













  • @George, thank you very much.

    – deepblue_86
    Jan 7 at 11:07






  • 1





    Another lazy trick is to use brace expansion with an empty string: cat file{,,} > new_file

    – wjandrea
    Jan 7 at 14:17














  • 2





    You couldn't even let the little guys take this one! Happy New Year Rav!

    – George Udosen
    Jan 7 at 10:53













  • :)) Happy to you too George ;)

    – Ravexina
    Jan 7 at 10:54













  • @George, thank you very much.

    – deepblue_86
    Jan 7 at 11:07






  • 1





    Another lazy trick is to use brace expansion with an empty string: cat file{,,} > new_file

    – wjandrea
    Jan 7 at 14:17








2




2





You couldn't even let the little guys take this one! Happy New Year Rav!

– George Udosen
Jan 7 at 10:53







You couldn't even let the little guys take this one! Happy New Year Rav!

– George Udosen
Jan 7 at 10:53















:)) Happy to you too George ;)

– Ravexina
Jan 7 at 10:54







:)) Happy to you too George ;)

– Ravexina
Jan 7 at 10:54















@George, thank you very much.

– deepblue_86
Jan 7 at 11:07





@George, thank you very much.

– deepblue_86
Jan 7 at 11:07




1




1





Another lazy trick is to use brace expansion with an empty string: cat file{,,} > new_file

– wjandrea
Jan 7 at 14:17





Another lazy trick is to use brace expansion with an empty string: cat file{,,} > new_file

– wjandrea
Jan 7 at 14:17


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1107686%2fduplicate-rows-in-text-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?