processing alternate line bash

awk, sed

Solution

$ cat input 
line1
this is line1
line2
this is line2
line3
this is line3
$ awk 'NR%2==1 {prev=$0} NR%2==0 {print prev ": " $0} END {if (NR%2==1) {print $0 ":"}}' input
line1: this is line1
line2: this is line2
line3: this is line3
$ 

Problem

I have a file like this ``` line1 this is line1 line2 this is line2 line3 this is line3 ``` I wanted to use awk or sed to remove trailing newline characters at every alternate line to merge them like this ``` line1: this is line1 line2: this is line2 line3: this is line3 ``` How do I do it using awk or sed

Original source