# nawk 'NR%3 {printf "%s ", $0;next}1(NR+1)%3{print"\n"}' infile The first line. Second line. First line of the second paragraph. Second line of the second paragraph.