Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joining a pair of lines with specific starting points

Tags:

linux

sed

I know that with sed I can print

cat current.txt | sed 'N;s/\n/,/'  > new.txt
A
B
C
D
E
F

to

A,B
C,D
E,F

What I would like to do is following:

A
B
C
D
E
F

to

A,D
B,E
C,F

I'd like to join 1 with 4, 2 with 5, 3 with 6 and so on. Is this possible with sed? Any idea how it could be achieved?

Thank you.

like image 217
MrD Avatar asked Mar 19 '23 23:03

MrD


1 Answers

Try printing in columns:

pr -s, -t -2 current.txt
like image 173
Scrutinizer Avatar answered Mar 25 '23 00:03

Scrutinizer