Convert a list to comma separated string and vice versa using sed and awk

This is a list of songs from Breaking Benjamin’s latest album Dark Before Dawn

cat list
Dark
Failure
Angels Fall
Breaking the Silence
Hollow
Close to Heaven
Bury Me Alive
Never Again
The Great Divide
Ashes of Eden
Defeated
Dawn

Lets convert this to a string of values separated by comma

awk -v "ORS=," '{print}' list
Dark,Failure,Angels Fall,Breaking the Silence,Hollow,Close to Heaven,Bury Me Alive,Never Again,The Great Divide,Ashes of Eden,Defeated,Dawn,

And lets convert this back to a list

awk -v "ORS=," '{print}' list | sed 's/,/\n/g'
Dark
Failure
Angels Fall
Breaking the Silence
Hollow
Close to Heaven
Bury Me Alive
Never Again
The Great Divide
Ashes of Eden
Defeated
Dawn
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s