karmag: Stylized face based on Dreamwidth logo (Default)
karmag ([personal profile] karmag) wrote in [community profile] command_liners 2011-12-30 10:27 am (UTC)

I don't know whether it's something BSD-specific or not, but rs can do this pretty elegantly too.

$ whatis rs
rs (1) - reshape a data array


Invoked as "rs -C, 1" it will convert an input separated by newlines to a comma separated output:

$ grep '^oxym' /usr/share/dict/words | rs -C, 1
oxymandelic,oxymel,oxymethylene,oxymoron,oxymuriate,oxymuriatic,


Plus you can undo the transformation too, if you pipe the comma separated input through "rs -c, 0 1" (lower case c).

The downside is that rs will leave you with a trailing comma, but as long as that's not an issue it's a pretty neat trick.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting