How to move every group of rows to a new column?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'd like to move every group of rows to columns this way.
Input:
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
Output:
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
I'm also adding actual example with some number below.
Input:
8.097e-10
7.099e-10
6.638e-10
6.395e-10
6.258e-10
6.180e-10
6.134e-10
6.108e-10
6.093e-10
Output:
8.097e-10 6.395e-10 6.134e-10
7.099e-10 6.258e-10 6.108e-10
6.638e-10 6.180e-10 6.093e-10
text-processing awk sed
add a comment |Â
up vote
2
down vote
favorite
I'd like to move every group of rows to columns this way.
Input:
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
Output:
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
I'm also adding actual example with some number below.
Input:
8.097e-10
7.099e-10
6.638e-10
6.395e-10
6.258e-10
6.180e-10
6.134e-10
6.108e-10
6.093e-10
Output:
8.097e-10 6.395e-10 6.134e-10
7.099e-10 6.258e-10 6.108e-10
6.638e-10 6.180e-10 6.093e-10
text-processing awk sed
1
Have you actually tried anything?
â Nasir Riley
Sep 2 at 22:56
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'd like to move every group of rows to columns this way.
Input:
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
Output:
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
I'm also adding actual example with some number below.
Input:
8.097e-10
7.099e-10
6.638e-10
6.395e-10
6.258e-10
6.180e-10
6.134e-10
6.108e-10
6.093e-10
Output:
8.097e-10 6.395e-10 6.134e-10
7.099e-10 6.258e-10 6.108e-10
6.638e-10 6.180e-10 6.093e-10
text-processing awk sed
I'd like to move every group of rows to columns this way.
Input:
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
Output:
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
I'm also adding actual example with some number below.
Input:
8.097e-10
7.099e-10
6.638e-10
6.395e-10
6.258e-10
6.180e-10
6.134e-10
6.108e-10
6.093e-10
Output:
8.097e-10 6.395e-10 6.134e-10
7.099e-10 6.258e-10 6.108e-10
6.638e-10 6.180e-10 6.093e-10
text-processing awk sed
edited yesterday
ñÃÂsýù÷
15.6k92563
15.6k92563
asked Sep 2 at 22:40
funfun
111
111
1
Have you actually tried anything?
â Nasir Riley
Sep 2 at 22:56
add a comment |Â
1
Have you actually tried anything?
â Nasir Riley
Sep 2 at 22:56
1
1
Have you actually tried anything?
â Nasir Riley
Sep 2 at 22:56
Have you actually tried anything?
â Nasir Riley
Sep 2 at 22:56
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
5
down vote
You can use the pr command:
pr -T -3 input_file > output_file
-3
means there'll be 3 columns-T
omits pagination of output
add a comment |Â
up vote
3
down vote
If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3
awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
If the rs
(reshape) utility is available, then
rs 0 3 < file | rs -T
or
paste - - - < file | rs -c -T
add a comment |Â
up vote
0
down vote
$ cat test.txt
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
$ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
You can use the pr command:
pr -T -3 input_file > output_file
-3
means there'll be 3 columns-T
omits pagination of output
add a comment |Â
up vote
5
down vote
You can use the pr command:
pr -T -3 input_file > output_file
-3
means there'll be 3 columns-T
omits pagination of output
add a comment |Â
up vote
5
down vote
up vote
5
down vote
You can use the pr command:
pr -T -3 input_file > output_file
-3
means there'll be 3 columns-T
omits pagination of output
You can use the pr command:
pr -T -3 input_file > output_file
-3
means there'll be 3 columns-T
omits pagination of output
answered Sep 2 at 22:53
choroba
24.5k34168
24.5k34168
add a comment |Â
add a comment |Â
up vote
3
down vote
If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3
awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
If the rs
(reshape) utility is available, then
rs 0 3 < file | rs -T
or
paste - - - < file | rs -c -T
add a comment |Â
up vote
3
down vote
If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3
awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
If the rs
(reshape) utility is available, then
rs 0 3 < file | rs -T
or
paste - - - < file | rs -c -T
add a comment |Â
up vote
3
down vote
up vote
3
down vote
If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3
awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
If the rs
(reshape) utility is available, then
rs 0 3 < file | rs -T
or
paste - - - < file | rs -c -T
If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3
awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
If the rs
(reshape) utility is available, then
rs 0 3 < file | rs -T
or
paste - - - < file | rs -c -T
answered Sep 2 at 23:21
steeldriver
32.1k34979
32.1k34979
add a comment |Â
add a comment |Â
up vote
0
down vote
$ cat test.txt
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
$ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
add a comment |Â
up vote
0
down vote
$ cat test.txt
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
$ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
add a comment |Â
up vote
0
down vote
up vote
0
down vote
$ cat test.txt
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
$ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
$ cat test.txt
R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3
$ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3
answered Sep 3 at 3:45
Kamaraj
2,7101312
2,7101312
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466465%2fhow-to-move-every-group-of-rows-to-a-new-column%23new-answer', 'question_page');
);
Post as a guest
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
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
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
1
Have you actually tried anything?
â Nasir Riley
Sep 2 at 22:56