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 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
add a comment |
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
See also superuser.com/q/338616/418028
– Sergiy Kolodyazhnyy
yesterday
add a comment |
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
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
bash text-processing
edited yesterday
Kulfy
3,84841140
3,84841140
asked yesterday
deepblue_86deepblue_86
5611023
5611023
See also superuser.com/q/338616/418028
– Sergiy Kolodyazhnyy
yesterday
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
See also superuser.com/q/338616/418028
– Sergiy Kolodyazhnyy
yesterday