How to combine alternate lines in a file?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a 4 line input file and i need to modify the file to combine alternate lines. I want to perform the operation in place.
INPUT:
Tom
Nathan
Jack
Polo
Desired Output:
Tom Jack
Nathan Polo
One way is to collect odd numbered lines and flip them and cut even numbered lines and combine both files to get the final output. But i am looking for a simpler solution.
text-processing awk sed paste
add a comment |Â
up vote
1
down vote
favorite
I have a 4 line input file and i need to modify the file to combine alternate lines. I want to perform the operation in place.
INPUT:
Tom
Nathan
Jack
Polo
Desired Output:
Tom Jack
Nathan Polo
One way is to collect odd numbered lines and flip them and cut even numbered lines and combine both files to get the final output. But i am looking for a simpler solution.
text-processing awk sed paste
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a 4 line input file and i need to modify the file to combine alternate lines. I want to perform the operation in place.
INPUT:
Tom
Nathan
Jack
Polo
Desired Output:
Tom Jack
Nathan Polo
One way is to collect odd numbered lines and flip them and cut even numbered lines and combine both files to get the final output. But i am looking for a simpler solution.
text-processing awk sed paste
I have a 4 line input file and i need to modify the file to combine alternate lines. I want to perform the operation in place.
INPUT:
Tom
Nathan
Jack
Polo
Desired Output:
Tom Jack
Nathan Polo
One way is to collect odd numbered lines and flip them and cut even numbered lines and combine both files to get the final output. But i am looking for a simpler solution.
text-processing awk sed paste
asked Jan 12 at 19:55
ayrton_senna
4922416
4922416
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
accepted
Given
$ cat INPUT
Tom
Nathan
Jack
Polo
then
$ pr -s -T -2 < INPUT
Tom Jack
Nathan Polo
(paginate with single tab spacing between columns, no headers, two columns); or
$ paste -d ' ' - - < INPUT | rs -T
Tom Jack
Nathan Polo
(paste then transpose)
What package provides thers
command?
â Wildcard
Jan 12 at 23:19
@Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simplyrs
- my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
â steeldriver
Jan 12 at 23:24
Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
â Wildcard
Jan 12 at 23:34
add a comment |Â
up vote
0
down vote
I have used below command to get the same.
I accept its complex one when compared to pr. But this is my try
for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab
output
Tom Jack
Nathan Polo
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Given
$ cat INPUT
Tom
Nathan
Jack
Polo
then
$ pr -s -T -2 < INPUT
Tom Jack
Nathan Polo
(paginate with single tab spacing between columns, no headers, two columns); or
$ paste -d ' ' - - < INPUT | rs -T
Tom Jack
Nathan Polo
(paste then transpose)
What package provides thers
command?
â Wildcard
Jan 12 at 23:19
@Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simplyrs
- my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
â steeldriver
Jan 12 at 23:24
Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
â Wildcard
Jan 12 at 23:34
add a comment |Â
up vote
5
down vote
accepted
Given
$ cat INPUT
Tom
Nathan
Jack
Polo
then
$ pr -s -T -2 < INPUT
Tom Jack
Nathan Polo
(paginate with single tab spacing between columns, no headers, two columns); or
$ paste -d ' ' - - < INPUT | rs -T
Tom Jack
Nathan Polo
(paste then transpose)
What package provides thers
command?
â Wildcard
Jan 12 at 23:19
@Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simplyrs
- my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
â steeldriver
Jan 12 at 23:24
Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
â Wildcard
Jan 12 at 23:34
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Given
$ cat INPUT
Tom
Nathan
Jack
Polo
then
$ pr -s -T -2 < INPUT
Tom Jack
Nathan Polo
(paginate with single tab spacing between columns, no headers, two columns); or
$ paste -d ' ' - - < INPUT | rs -T
Tom Jack
Nathan Polo
(paste then transpose)
Given
$ cat INPUT
Tom
Nathan
Jack
Polo
then
$ pr -s -T -2 < INPUT
Tom Jack
Nathan Polo
(paginate with single tab spacing between columns, no headers, two columns); or
$ paste -d ' ' - - < INPUT | rs -T
Tom Jack
Nathan Polo
(paste then transpose)
edited Jan 12 at 22:55
answered Jan 12 at 20:03
steeldriver
31.6k34979
31.6k34979
What package provides thers
command?
â Wildcard
Jan 12 at 23:19
@Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simplyrs
- my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
â steeldriver
Jan 12 at 23:24
Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
â Wildcard
Jan 12 at 23:34
add a comment |Â
What package provides thers
command?
â Wildcard
Jan 12 at 23:19
@Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simplyrs
- my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
â steeldriver
Jan 12 at 23:24
Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
â Wildcard
Jan 12 at 23:34
What package provides the
rs
command?â Wildcard
Jan 12 at 23:19
What package provides the
rs
command?â Wildcard
Jan 12 at 23:19
@Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply
rs
- my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?â steeldriver
Jan 12 at 23:24
@Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply
rs
- my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?â steeldriver
Jan 12 at 23:24
Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
â Wildcard
Jan 12 at 23:34
Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
â Wildcard
Jan 12 at 23:34
add a comment |Â
up vote
0
down vote
I have used below command to get the same.
I accept its complex one when compared to pr. But this is my try
for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab
output
Tom Jack
Nathan Polo
add a comment |Â
up vote
0
down vote
I have used below command to get the same.
I accept its complex one when compared to pr. But this is my try
for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab
output
Tom Jack
Nathan Polo
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I have used below command to get the same.
I accept its complex one when compared to pr. But this is my try
for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab
output
Tom Jack
Nathan Polo
I have used below command to get the same.
I accept its complex one when compared to pr. But this is my try
for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab
output
Tom Jack
Nathan Polo
answered Jan 13 at 4:38
Praveen Kumar BS
1,010128
1,010128
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%2f416663%2fhow-to-combine-alternate-lines-in-a-file%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