Bash 将文本多行合并为一行与规范。数据

Bash text multi line into one line with spec. data

我得到了这样的东西

Title  : Magic Moments                   Artist: Perry Como
Album  : Original American Songbook: 50  Year: 2005, Genre: Other (12)
Comment: DrBN                            Track: 7

我需要这个

Magic Moments,Perry Como,Original American Songbook: 50,2005,Other (12),DrBN,7

我是 bash 的新手,我不知道怎样才能得到这个 感谢您的帮助!

编辑

Title  : Magic Moments                   Artist: Perry Como                    
Album  : Original American Songbook: 50  Year: 2005, Genre: Other (12)
Comment: DrBN                            Track: 7
Title  : Stormy Weather                  Artist: Frank Sinatra                 
Album  : Original American Songbook: 50  Year: 2005, Genre: Other (12)
Comment: DrBN                            Track: 8
Title  : Let There Be Love               Artist: Sammy Davis, Jr.              
Album  : Original American Songbook: 50  Year: 2005, Genre: Other (12)
Comment: DrBN                            Track: 9
Title  : Makin' Whoopee                  Artist: Esther Williams               
Album  : Original American Songbook: 50  Year: 2005, Genre: Other (12)
Comment: DrBN                            Track: 10
Title  : Spanish Eyes                    Artist: Al Martino                    
Album  : Original American Songbook: 50  Year: 2005, Genre: Other (12)
Comment: DrBN                            Track: 11
Title  : 'S Wonderful {From An American  Artist: Gene Kelly; Georges Guétary   
Album  : Original American Songbook: 50  Year: 2005, Genre: Other (12)
Comment: DrBN                            Track: 12
Title  : Out Of My Head                  Artist: John Newman                   
Album  : Tribute (Deluxe Edition)        Year: 2013, Genre: Pop (13)
Comment: no coment                       Track: 6

使用 sedpaste,如

sed 's/Title *: //;s/ *Artist: /,/;s/Album *: //; s/ *Year: /,/;s/ *Genre: //;s/Comment: //;s/ *Track: /,/' | paste -sd,

当然,如果你有多个records/albums/tracks,或者字段名可能会发生变化,还有更好的解决方案。