Hi,
I want to truncate a string variable, returned in the script. In perl I used the below and it worked.
BRNo=BR12345
$BR = substr($BRNo, 2, 7)
How can I do it in sh.
Thanks !
Hi,
I want to truncate a string variable, returned in the script. In perl I used the below and it worked.
BRNo=BR12345
$BR = substr($BRNo, 2, 7)
How can I do it in sh.
Thanks !
echo 'BR12345' | sed 's/^..\(.....\).*/\1/'
$ expr $BRNo : '..\(.....\)'
12345
$ expr $BRNo : '..\(.\{5\}\)'
12345
Two other ways for substrings :
$ Str=123456789
$ s1=$(expr substr "${Str}" 2 3)
$ echo $s1
234
$ s2=${Str:1:3} # bash
$ echo $s2
234
$
Jean-Pierre.
brno=br12345
br=`echo $brno|cut -c3-7`
Jean, You missed the assignment statement to s1 variable
in ksh, just use a variable declaration:
typeset -L5 x
x=aslkdhflaalkshdlkhasd
echo $x
aslkd
Thanks everyone, I got it to work !
Oups!
Missing statement added, was :
$ s1=$(expr substr "${Str}" 2 3)
Jean-Pierre.