
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tlug] Joining lists on the command line
2009/9/11 BALUTA Chris <baluta@example.com>:
> Leo Howell wrote:
>
>> What's the most unixy way to put them into a comma-separated list using
>> the command line?
>
> Well, I think almost by definition there isn't a 'most
> unixy' way to do much of anything, which is one of the fun things
> about the unix command line.
>
> But, how about this: echo `<your command>` | sed -e 's/ /,/g'
>
> For example, say ls gives this:
>
> myprompt> ls
> afile bfile cfile dfile theLastFile
>
> myprompt> echo `ls` | sed -e 's/ /,/g'
>
> gives:
> afile,bfile,cfile,dfile,theLastFile
>
> myprompt> echo `seq 1 20` | sed -e 's/ /,/g'
>
> leads to:
> 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
>
> Of course, you'll have problems w/spaces if your command
> output for one line has spaces in it (e.g. output from grep)...
Not very short, but hopefully meets some sort of "unixy" criteria and
doesn't have the space problem:
ls | perl -e 'while(<>) { chomp; push @l, $_ }; print join(",",@l);'
To make it short you could of course just put the perl into its own
shell script file...
Ian Barwick
Home |
Main Index |
Thread Index