ur subst version is best and fastest
, the my last version seems buggy

its to filter out numbers
.. just a bit related to the topic sorry ..

++ greets ++

On Tue, Feb 11, 2025, 10:23 AM Phi Debian <phi.deb...@gmail.com> wrote:

>
> Can follow that fast, the n-1 version gives
>
> gimme_num( ) { local y o m='[0-9,.]' s=$'\n' i t ; t="(-?$m+)" ; unset -v
> o ; for n ; do unset -v i ; while [[ $n =~ $t ]] ; do y=${BASH_REMATCH[1]}
> n=${n/"$y"} i= o+=$y$s ; done ; [[ -v i ]] && o+=$s ; done ; [[ -v o ]] &&
> printf %s "$o" ; }
> $ gimme_num 0x10 60#yo 0x10
> 0
> 10
>
> 60
>
> 0
> 10
>
> That can be streamlined as
> $ gimme_num2()
> { printf '%d\n' ${@//[^0-9]/ }
> }
> $ gimme_num2 0x10 60#yo 0x10
> 0
> 10
> 60
> 0
> 10
>
> The last version gives
>
> $ gimme_num( ) { local y o m='[0-9,.]' s=$'\n' i t ; t="(-?$m+)" ; unset
> -v o ; for n ; do i= ; if [[ $n =~ $t ]] ; then while [[ -v
> BASH_REMATCH[++i] ]] ; do o+=${BASH_REMATCH[i]}$s ; done ; fi ; [[ $i != 1
> ]] && o+=$s ; done ; [[ -v o ]] && printf %s "$o" ; }
> $ gimme_num 0x10 60#yo 0x10
> 0
>
> 60
>
> 0
>
> Dunno what use case I could do with that
>
>
>

Reply via email to