sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)
Sophie ([personal profile] sophie) wrote in [community profile] command_liners2011-12-29 08:40 pm

Generating a comma-separated list from grep

Sometimes you want to paste the output of a grep command into IRC or IM, and don't want each match on a separate line. Fortunately, it's easy to convert it to a comma-separated list instead - simply pipe the output through xargs echo | sed 's/ /, /g'. So, for example, instead of:

Sophie@Sophie-Laptop:~/primtionary$ grep cuddle american-english-insane
cuddle
cuddleable
cuddled
cuddler
cuddlers
cuddles
cuddlesome
scuddle
scuddled
scuddles
upscuddle


...you get:

Sophie@Sophie-Laptop:~/primtionary$ grep cuddle american-english-insane | xargs echo | sed 's/ /, /g'
cuddle, cuddleable, cuddled, cuddler, cuddlers, cuddles, cuddlesome, scuddle, scuddled, scuddles, upscuddle


Very useful sometimes :D
jld: Batman says, “An *Amazon* attack, a deadly *bee* weapon... Bees.  My God.” (bee weapon)

[personal profile] jld 2011-12-30 05:35 am (UTC)(link)
That xargs makes me twitchy...

grep '^it.' /usr/share/dict/words | xargs echo


Or, for more fun, on a GNU system:

xargs echo << EOT
-e
\\\\e[40;33;1m
BEES
BEES
BEES
EOT