Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting Two Consecutive Lines into One Line with Perl / AWK

I have a data like below:

abcd
join abcd
efgh
join efgh

I want to join the two consecutive pair into one line. Resulting:

abcd join abcd
efgh join efgh

How can I do it in Perl/AWK?

like image 504
neversaint Avatar asked Nov 27 '22 06:11

neversaint


2 Answers

$ sed 'N;s/\n/ /' input.txt
abcd join abcd
efgh join efgh
like image 150
kev Avatar answered Nov 29 '22 20:11

kev


The simplest way is:

paste - - < FILE

This joins using a space instead of a tab:

paste -d" " - - < FILE
like image 36
yazu Avatar answered Nov 29 '22 19:11

yazu