Hi,
Suppose there is a string
x.y.z , where x, y & z could be any integer from 0-999.
How do I extract the value of z?
Also how to extract "x.y" ?
I'm OK with using sh, sed, awk grep or cut.
Please help me figure this out.
Thanks
Hi,
Suppose there is a string
x.y.z , where x, y & z could be any integer from 0-999.
How do I extract the value of z?
Also how to extract "x.y" ?
I'm OK with using sh, sed, awk grep or cut.
Please help me figure this out.
Thanks
What is your sh? This is normally a link to e.g. bash, ksh or tcsh. Given bash:
$ a=x.y.z
$ echo ${a//*.}
z
.. and the answer for OP's second question, if the shell support Parameter Expansion
echo ${a##*.}
echo ${a%.*}
.. if not you can use cut(beside other)
echo x.y.z | cut -d '.' -f3
echo x.y.z | cut -d '.' -f1-2
if you have distinct field delimiters like that, ie ".", its easier to use fields than parameter expansion or substitution.
# a=x.y.z
# IFS="."
# set -- $a
# echo $1
x
# echo $2
y
# echo $3
z
cat filename | cut -d"." -f3
Thanks a lot guys....
I appreciate your help.