切割均匀线并合并至上线

切割均匀线并合并至上线

我有一个带有 CRLF 行终止符的文件:

Green Day: Rock Band Xbox 360
3074
Green Hell Steam
27015-27030, 27036-27037
Green Hell Switch
6667, 12400, 28910, 29900, 29901, 29920
Adios Steam

Adios Xbox One

Adore Playstation 4
3074, 3478-3479

偶数行中也有一些空行。我怎样才能剪切偶数行并附加到其上一行?像这样:(第一行后面必须有逗号)

first line, second line

Green Day: Rock Band Xbox 360, 3074
Green Hell Steam, 27015-27030, 27036-27037
Green Hell Switch, 6667, 12400, 28910, 29900, 29901, 29920
Adios Steam,
Adios Xbox One,
Adore Playstation 4, 3074, 3478-3479

答案1

首先,将输入文件传递给dos2unix实用程序以删除 Windows 行尾\r

$ awk 'NR%2{printf "%s, ", $0;next}1' file
Green Day: Rock Band Xbox 360, 3074
Green Hell Steam, 27015-27030, 27036-27037
Green Hell Switch, 6667, 12400, 28910, 29900, 29901, 29920
Adios Steam, 
Adios Xbox One, 
Adore Playstation 4, 3074, 3478-3479

相关内容