string handling doubt
3 posters
string handling doubt
$ echo $str
abbcccddddeeeeeffffff
$ expr "$str" : '[^d]*d'
7
from the above i can find that its returning the first position of "d" but how???
abbcccddddeeeeeffffff
$ expr "$str" : '[^d]*d'
7
from the above i can find that its returning the first position of "d" but how???
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: string handling doubt
[^d]* specifies 0 or more occurence of any character other than d ....
[^d]*d specifies the first occurence of d after 0 or more occurence of any character other than d ....
[^d]*d specifies the first occurence of d after 0 or more occurence of any character other than d ....
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: string handling doubt
but i get
[336474@oracleclient ~]$ expr "$str" : '[^e]*d'
10
why does it so??
@akalya form ur explanation
the above [^e]*d must mean
the first occurrence of d after 0 or more occurrence of any character other than e.
so it must have returned 7 but y does this return 10???
[336474@oracleclient ~]$ expr "$str" : '[^e]*d'
10
why does it so??
@akalya form ur explanation
the above [^e]*d must mean
the first occurrence of d after 0 or more occurrence of any character other than e.
so it must have returned 7 but y does this return 10???
Re: string handling doubt
@ganesh
7th position has the first occurence of d....
[^e]* means it allows any character except e..which means d also can occur any number of times...
therefore it gives the last occurence of d jus b4 any e is encountered..
[335802@oracleclient ~]$ str=abbcccddddeeeeefffdddfffgddd
[335802@oracleclient ~]$ expr "$str" : '[^d]*d'
7
[335802@oracleclient ~]$ expr "$str" : '[^e]*d'
10
[335802@oracleclient ~]$ expr "$str" : '[^f]*d'
10
[335802@oracleclient ~]$ expr "$str" : '[^g]*d'
21
[335802@oracleclient ~]$ expr "$str" : '[^a]*d'
0
[335802@oracleclient ~]$ expr "$str" : '[^b]*d'
0
[335802@oracleclient ~]$ expr "$str" : '[^c]*d'
0
7th position has the first occurence of d....
[^e]* means it allows any character except e..which means d also can occur any number of times...
therefore it gives the last occurence of d jus b4 any e is encountered..
[335802@oracleclient ~]$ str=abbcccddddeeeeefffdddfffgddd
[335802@oracleclient ~]$ expr "$str" : '[^d]*d'
7
[335802@oracleclient ~]$ expr "$str" : '[^e]*d'
10
[335802@oracleclient ~]$ expr "$str" : '[^f]*d'
10
[335802@oracleclient ~]$ expr "$str" : '[^g]*d'
21
[335802@oracleclient ~]$ expr "$str" : '[^a]*d'
0
[335802@oracleclient ~]$ expr "$str" : '[^b]*d'
0
[335802@oracleclient ~]$ expr "$str" : '[^c]*d'
0
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Similar topics
» how to use a string as a delimiter?
» doubt in sed cmd
» doubt in tr
» unix cmd doubt
» tee command doubt
» doubt in sed cmd
» doubt in tr
» unix cmd doubt
» tee command doubt
Permissions in this forum:
You cannot reply to topics in this forum