Thread: grep & regexp
View Single Post

   
  #5 (permalink)  
Old 02-15-2008, 10:44 AM
John DuBois
 
Posts: n/a
Default Re: grep & regexp

In article <20031003131943.A13414@trebor.iglou.com>,
Bob Stockler <bob@trebor.iglou.com> wrote:
>Since you said "ksh", use its parameter substitution:
>
> myvar="123.4567"
> myvar=${myvar%[0-9][0-9]}
>
>If the value might be:
>
> 123.45
> 123.456
> 123.4567
> 123.45678
> ......
>
>use a case-esac construction to supply the proper
>parameter substitution for the input variable.


Or something like:

a=123.45678
tail=${a#*.??}
[[ $tail != $a ]] && a=${a%$tail}

John
--
John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Reply With Quote