From: hehe2046 on
You don't need sed. bash is enough and fast

for fl in $(ls *spkg);do
echo ${fl%%-*}
done




From: Mart Frauenlob on
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
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.
>