Skip to content
Advertisement

Bash text multi line into one line with spec. data

I got something like this

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

And I need this

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

I am new with the bash and I dont know how can I get this Thanks for you help!

EDIT

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

Advertisement

Answer

Use sed and paste, as in

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

Of course, if you have multiple records/albums/tracks, or if the field names may change, there are better solutions.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement