使用spec将Bash文本多行压缩成一行。数据

时间:2017-05-03 11:52:34

标签: linux bash tex

我有类似的东西

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

1 个答案:

答案 0 :(得分:0)

使用sedpaste,如

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

当然,如果您有多个记录/专辑/曲目,或者字段名称可能会更改,则有更好的解决方案。