Issue
I need to join every other line in a file with the line after it.
1, 2
3, 4
5, 6
7, 8
9, 10
11, 12
The output should be like:
1, 2, 3, 4
5, 6, 7, 8
9, 10, 11, 12
I have used awk '{getline b;printf("%s,%s\n",$0,b)}' file
. However, the output is:
1, 2
,3, 4
5, 6
,7, 8
9, 10
,11, 12
I wonder how each line can be concatenated with the line after it.
Solution
You can use
sed 'N;s/\n/, /' file
This N appends the next line and s command substitutes the newline with a comma and space.
The output is:
1, 2, 3, 4
5, 6, 7, 8
9, 10, 11, 12
Answered By - bkmoney Answer Checked By - Senaida (WPSolving Volunteer)