Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Joining lists on the command line
- Date: Fri, 11 Sep 2009 17:09:59 +0900
- From: Ian Barwick <barwick@example.com>
- Subject: Re: [tlug] Joining lists on the command line
- References: <20090911055611.GB5688@example.com> <20090911062647.GB24338@example.com>
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
- Follow-Ups:
- Re: [tlug] Joining lists on the command line
- From: Andrew Grover
- References:
- [tlug] Joining lists on the command line
- From: Leo Howell
- Re: [tlug] Joining lists on the command line
- From: BALUTA Chris
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] router
- Next by Date: Re: [tlug] Joining lists on the command line
- Previous by thread: Re: [tlug] Joining lists on the command line
- Next by thread: Re: [tlug] Joining lists on the command line
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links