ksh93
ksh93
(OP)
In ksh93, I want to match on a string and be able to print out the subpatterns like I do in perl.
Given the following:
line="abc (hij) = lmn"
if [[ $line = @(*[a-z]\(*[a-z]\)=*[a-z]) ]]; then
v1=${.sh.match[1]}
v2=${.sh.match[2]}
v3=${.sh.match[3]}
print "v1=$v1 \nv2=$v2\nv3=$v3"
fi
What would do to emit the different pieces of this string? ie, to get v1=abc v2=hij v3=lmn ?
Nothing I try comes close to working.
I have a bunch of perl I've been told to convert into ksh so this answer would help a lot.
thx
Given the following:
line="abc (hij) = lmn"
if [[ $line = @(*[a-z]\(*[a-z]\)=*[a-z]) ]]; then
v1=${.sh.match[1]}
v2=${.sh.match[2]}
v3=${.sh.match[3]}
print "v1=$v1 \nv2=$v2\nv3=$v3"
fi
What would do to emit the different pieces of this string? ie, to get v1=abc v2=hij v3=lmn ?
Nothing I try comes close to working.
I have a bunch of perl I've been told to convert into ksh so this answer would help a lot.
thx
RE: ksh93
CODE
RE: ksh93
The "sed" command is just turning the parenthesis and equal sign into spaces so the "read" sees the values as separate values.
This could also be done with "awk" if you want just certain values from the line, or you need some conditional logic in there too.
RE: ksh93
So, if anyone knows hows to do this using only ksh93 that would be great.
RE: ksh93
Then use a regular expression like you do in Perl :
CODE --> ksh93 ( fragment )
Feherke.
feherke.ga
RE: ksh93
Thanks Feherke!
RE: ksh93
CODE
RE: ksh93
But, my example was a simple one I provided in order to learn how to do the much more complex ones I need.
Thanks for the reply however.
RE: ksh93
CODE