repeat a list of data in the same file/column
I have a list of data in a file such as
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
and I would like to repeat this sequence of data 35 times so to have an output file such as
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.(x35 times)
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
text-processing awk
add a comment |
I have a list of data in a file such as
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
and I would like to repeat this sequence of data 35 times so to have an output file such as
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.(x35 times)
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
text-processing awk
Does it have to be awk? with perl, you could do something likeperl -00 -ne 'print $_ x 35' file
– steeldriver
Dec 23 '18 at 17:59
Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:23
In a cshell you can do simply:repeat 35 cat data_file
– Rakesh Sharma
Dec 26 '18 at 4:29
add a comment |
I have a list of data in a file such as
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
and I would like to repeat this sequence of data 35 times so to have an output file such as
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.(x35 times)
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
text-processing awk
I have a list of data in a file such as
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
and I would like to repeat this sequence of data 35 times so to have an output file such as
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.(x35 times)
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
text-processing awk
text-processing awk
edited Dec 23 '18 at 18:58
Jeff Schaller
40.9k1056131
40.9k1056131
asked Dec 23 '18 at 17:51
Dimitris MintisDimitris Mintis
805
805
Does it have to be awk? with perl, you could do something likeperl -00 -ne 'print $_ x 35' file
– steeldriver
Dec 23 '18 at 17:59
Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:23
In a cshell you can do simply:repeat 35 cat data_file
– Rakesh Sharma
Dec 26 '18 at 4:29
add a comment |
Does it have to be awk? with perl, you could do something likeperl -00 -ne 'print $_ x 35' file
– steeldriver
Dec 23 '18 at 17:59
Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:23
In a cshell you can do simply:repeat 35 cat data_file
– Rakesh Sharma
Dec 26 '18 at 4:29
Does it have to be awk? with perl, you could do something like
perl -00 -ne 'print $_ x 35' file
– steeldriver
Dec 23 '18 at 17:59
Does it have to be awk? with perl, you could do something like
perl -00 -ne 'print $_ x 35' file
– steeldriver
Dec 23 '18 at 17:59
Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:23
Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:23
In a cshell you can do simply:
repeat 35 cat data_file
– Rakesh Sharma
Dec 26 '18 at 4:29
In a cshell you can do simply:
repeat 35 cat data_file
– Rakesh Sharma
Dec 26 '18 at 4:29
add a comment |
4 Answers
4
active
oldest
votes
With simple for
loop:
for i in {1..35}; do cat input_file >> new_file; done
Consider implementing the loop viawhile
with counter. The{1..35}
works inbash
andksh
( IIRC ) but not in POSIX/bin/sh
.
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:24
add a comment |
For exactly that input data structure (i.e. no empty lines), and for awk
s that allow for it (i.e. the last line read is available in the END
section), try
$ awk 'END {for (i=1; i=35; i++) print}' RS= file
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
EDIT: or, even shorter,
awk 'END {for (i=35; i--;) print}' RS= file
add a comment |
In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:
awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt
Of course, if the number of lines in file is very large it would be more appropriate to cat
the file multiple times and append as shown in Roman's answer
add a comment |
yes input_file | sed 35q | xargs cat > output_file
or with awk
:
awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f490634%2frepeat-a-list-of-data-in-the-same-file-column%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
With simple for
loop:
for i in {1..35}; do cat input_file >> new_file; done
Consider implementing the loop viawhile
with counter. The{1..35}
works inbash
andksh
( IIRC ) but not in POSIX/bin/sh
.
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:24
add a comment |
With simple for
loop:
for i in {1..35}; do cat input_file >> new_file; done
Consider implementing the loop viawhile
with counter. The{1..35}
works inbash
andksh
( IIRC ) but not in POSIX/bin/sh
.
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:24
add a comment |
With simple for
loop:
for i in {1..35}; do cat input_file >> new_file; done
With simple for
loop:
for i in {1..35}; do cat input_file >> new_file; done
answered Dec 23 '18 at 17:59
RomanPerekhrestRomanPerekhrest
23k12447
23k12447
Consider implementing the loop viawhile
with counter. The{1..35}
works inbash
andksh
( IIRC ) but not in POSIX/bin/sh
.
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:24
add a comment |
Consider implementing the loop viawhile
with counter. The{1..35}
works inbash
andksh
( IIRC ) but not in POSIX/bin/sh
.
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:24
Consider implementing the loop via
while
with counter. The {1..35}
works in bash
and ksh
( IIRC ) but not in POSIX /bin/sh
.– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:24
Consider implementing the loop via
while
with counter. The {1..35}
works in bash
and ksh
( IIRC ) but not in POSIX /bin/sh
.– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:24
add a comment |
For exactly that input data structure (i.e. no empty lines), and for awk
s that allow for it (i.e. the last line read is available in the END
section), try
$ awk 'END {for (i=1; i=35; i++) print}' RS= file
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
EDIT: or, even shorter,
awk 'END {for (i=35; i--;) print}' RS= file
add a comment |
For exactly that input data structure (i.e. no empty lines), and for awk
s that allow for it (i.e. the last line read is available in the END
section), try
$ awk 'END {for (i=1; i=35; i++) print}' RS= file
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
EDIT: or, even shorter,
awk 'END {for (i=35; i--;) print}' RS= file
add a comment |
For exactly that input data structure (i.e. no empty lines), and for awk
s that allow for it (i.e. the last line read is available in the END
section), try
$ awk 'END {for (i=1; i=35; i++) print}' RS= file
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
EDIT: or, even shorter,
awk 'END {for (i=35; i--;) print}' RS= file
For exactly that input data structure (i.e. no empty lines), and for awk
s that allow for it (i.e. the last line read is available in the END
section), try
$ awk 'END {for (i=1; i=35; i++) print}' RS= file
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
EDIT: or, even shorter,
awk 'END {for (i=35; i--;) print}' RS= file
answered Dec 23 '18 at 22:31
RudiCRudiC
4,2441312
4,2441312
add a comment |
add a comment |
In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:
awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt
Of course, if the number of lines in file is very large it would be more appropriate to cat
the file multiple times and append as shown in Roman's answer
add a comment |
In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:
awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt
Of course, if the number of lines in file is very large it would be more appropriate to cat
the file multiple times and append as shown in Roman's answer
add a comment |
In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:
awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt
Of course, if the number of lines in file is very large it would be more appropriate to cat
the file multiple times and append as shown in Roman's answer
In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:
awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt
Of course, if the number of lines in file is very large it would be more appropriate to cat
the file multiple times and append as shown in Roman's answer
answered Dec 23 '18 at 22:31
Sergiy KolodyazhnyySergiy Kolodyazhnyy
10.1k32660
10.1k32660
add a comment |
add a comment |
yes input_file | sed 35q | xargs cat > output_file
or with awk
:
awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file
add a comment |
yes input_file | sed 35q | xargs cat > output_file
or with awk
:
awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file
add a comment |
yes input_file | sed 35q | xargs cat > output_file
or with awk
:
awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file
yes input_file | sed 35q | xargs cat > output_file
or with awk
:
awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file
edited Dec 24 '18 at 6:04
answered Dec 23 '18 at 18:04
Uncle BillyUncle Billy
4755
4755
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f490634%2frepeat-a-list-of-data-in-the-same-file-column%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
Does it have to be awk? with perl, you could do something like
perl -00 -ne 'print $_ x 35' file
– steeldriver
Dec 23 '18 at 17:59
Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
– Sergiy Kolodyazhnyy
Dec 23 '18 at 22:23
In a cshell you can do simply:
repeat 35 cat data_file
– Rakesh Sharma
Dec 26 '18 at 4:29