I have written some code in a KSH script to find the index of the character in a string like this
#!usr/bin/ksh
string="Hi How are you"
awk 'BEGIN {print index ($string, "are")}'
My expected output should be : 8
but it is giving the out put as : 0
I wanted to store that index value in a variable. Can anyone please help me in this
Also I am trying to get a substring of the above string by providing the start index and end index and store the substring in another variable. I am not getting any clue how to do that.
#!/usr/bin/ksh
echo "-------START-----"
string="Hi How are you"
nawk -v s="$string" 'BEGIN {print index (s, "are")}'
echo "-------END-------"
Or
#!/usr/bin/ksh
echo "-------START-----"
string="Hi How are you"
/usr/xpg4/bin/awk -v s="$string" 'BEGIN {print index (s, "are")}'
echo "-------END-------"