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
    yesterday
















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
    yesterday














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 yesterday









Kulfy

3,84841140




3,84841140










asked yesterday









deepblue_86deepblue_86

5611023




5611023












  • See also superuser.com/q/338616/418028
    – Sergiy Kolodyazhnyy
    yesterday


















  • See also superuser.com/q/338616/418028
    – Sergiy Kolodyazhnyy
    yesterday
















See also superuser.com/q/338616/418028
– Sergiy Kolodyazhnyy
yesterday




See also superuser.com/q/338616/418028
– Sergiy Kolodyazhnyy
yesterday










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
    yesterday












  • :)) Happy to you too George ;)
    – Ravexina
    yesterday












  • @George, thank you very much.
    – deepblue_86
    yesterday






  • 1




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











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
    yesterday












  • :)) Happy to you too George ;)
    – Ravexina
    yesterday












  • @George, thank you very much.
    – deepblue_86
    yesterday






  • 1




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
















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
    yesterday












  • :)) Happy to you too George ;)
    – Ravexina
    yesterday












  • @George, thank you very much.
    – deepblue_86
    yesterday






  • 1




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














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 yesterday

























answered yesterday









RavexinaRavexina

31.6k1482111




31.6k1482111








  • 2




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












  • :)) Happy to you too George ;)
    – Ravexina
    yesterday












  • @George, thank you very much.
    – deepblue_86
    yesterday






  • 1




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














  • 2




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












  • :)) Happy to you too George ;)
    – Ravexina
    yesterday












  • @George, thank you very much.
    – deepblue_86
    yesterday






  • 1




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








2




2




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






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














:)) Happy to you too George ;)
– Ravexina
yesterday






:)) Happy to you too George ;)
– Ravexina
yesterday














@George, thank you very much.
– deepblue_86
yesterday




@George, thank you very much.
– deepblue_86
yesterday




1




1




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




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


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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

1300-talet

1300-talet

Display a custom attribute below product name in the front-end Magento 1.9.3.8