I have the following data (a list of R packages parsed from a Rmarkdown file), that I want to turn into a list I can pass to R to install:d3heatmapdata.tableggplot2htmltoolshtmlwidgetsmetricsgraphicsnetworkD3plotlyreshape2scalesstringrI want to turn the list into a list of the form:'d3heatmap', 'data.table', 'ggplot2', 'htmltools', 'htmlwidgets', 'metricsgraphics', 'networkD3', 'plotly', 'reshape2', 'scales', 'stringr'I currently have a bash pipeline that goes from the raw file to the list above:grep 'library(' Presentation.Rmd \| grep -v '#' \| cut -f2 -d\( \| tr -d ')'  \| sort | uniqI want to add a step on to turn the new lines into the comma separated list. I've tried adding tr '\n' ',', which fails. I've also tried a number of the following Stack Overflow answers, which also fail:https://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sedThis produces library(stringr)))phics) as the result.https://stackoverflow.com/questions/10748453/replace-comma-with-newline-in-sedThis produces ,% as the result.Can sed replace new line characters?This answer (with the -i flag removed), produces output identical to the input.
Turning separate lines into a comma separated list with quoted entries
linux;sed;csv;tr
You can add quotes with sed and then merge lines with paste, like that:sed 's/^\|$//g'|paste -sd, -If you are running a GNU coreutils based system (i.e. Linux), you can omit the trailing '-'.If you input data has DOS-style line endings (as @phk suggested), you can modify the command as follows:sed 's/\r//;s/^\|$//g'|paste -sd, -