Okay, this one actually works, and it is a true replica of the Boyer-Moore algorithm:
Sorry for messing up the last post.Code:#!/bin/bash # Boyer-Moore string search # inputs: $1 - substring, $2 - string declare -i index=-1; for((i=0; i < ${#2}; i++)) do for((j=${#1}-1; j >= 0; j--)) # loop for individual substring comparisons do if [ "${1:j:1}" = "${2:i+j:1}" ] # compares backward then index=i; else index=-1; i+=(${#1}-j); # Boyer-Moore jump break; fi done if [ $index -ne -1 ] then break; # stop if substring has been found fi done echo $index; unset index;
Life's too short to be cool. Be a nerd.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks