Prev: Trekking, Mountaineering and expeditions in Nepal
Next: Redirect stdout and stderr preserving the original order
From: hehe2046 on 2 Aug 2010 03:58 You don't need sed. bash is enough and fast for fl in $(ls *spkg);do echo ${fl%%-*} done
From: Mart Frauenlob on 2 Aug 2010 05:46 On 02.08.2010 09:58, hehe2046 wrote: > You don't need sed. bash is enough and fast > > for fl in $(ls *spkg);do > echo ${fl%%-*} > done no need for the error prone ls subshell. '%%-*' removes all hyphens. that would trim boost-cropped-1.34.1.spkg too far. cd /whatever/dir for x in *; do printf "%s\n" "${x%-*}"; done there's one downside i know of - if the directory does not contain any files, the globbing pattern is shown (afaik sh, bash, ksh, more?): cd /tmp/t/ # for x in *; do printf "%s\n" "$x"; done * # one might 'test -[e|f]' to work around, but that slows down the whole thing. best regards mart
From: Mart Frauenlob on 2 Aug 2010 07:32
On 02.08.2010 11:46, Mart Frauenlob wrote: [...] > cd /whatever/dir > for x in *; do printf "%s\n" "${x%-*}"; done > > there's one downside i know of - if the directory does not contain any > files, the globbing pattern is shown (afaik sh, bash, ksh, more?): I should have said, 'not any matching files'... > > cd /tmp/t/ > # for x in *; do printf "%s\n" "$x"; done > * > # > also to mention that it'll also list directories... > one might 'test -[e|f]' to work around, but that slows down the whole > thing. > |