Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

find index of string in shell

# To find the index of a substring in another string
# Take for instance, below take two strings: str and substr. 

str="hello world"
substr="world"
 
prefix=${str%%$substr*}
index=${#prefix}
 
if [[ index -eq ${#str} ]];
then
    echo "Substring is not present in string."
else
    echo "Index of substring in string : $index"
fi

Source by www.tutorialkart.com #
 
PREVIOUS NEXT
Tagged: #find #index #string #shell
ADD COMMENT
Topic
Name
6+7 =