Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Joining lists on the command line



Hi TLUG,

Say you have a list of items, one per line, such as the output of 
"ls", "grep" or whatever. As an example, how about:

	seq 5

which just gives the numbers 1 to 5.

What's the most unixy way to put them into a comma-separated list using 
the command line?

The command I used (adjusted for the example above) was

	seq 5 | xargs -n1 -I$ echo -n $,

Which almost works, except there is a trailing comma and no newline. I 
know this can be fixed with a slightly longer command, but it served my 
purposes.

While writing this email, I came up with

	seq 5 | tr '\n' ,

which is shorter, but provides the same output.

Can anyone think of something better? I feel like I'm missing something 
obvious - and there's already a different utility called "join".


Leo


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links