consider the following example:
string1=dogs
string2 = animalsdogscatsdogs
now i need to find the starting position of string1 within string2 specified from a given position.
if d = [string1,string2]
then the value of d will be 8 as dogs starts from the 8th position in string2
now if d = [string1,string2,5]
then the value of d will be 8 since the starting position is from 5th position but still dogs start from position 8 in string2.
now if d = [string1,string2,10]
then the value of d will be 16 as the matching starts from position 10.
i need to atain the same functionality as described above usind awk or nawk or C SHELL.
I HAVE ATTAINED THE ABOVE FUNCTIONALITY USING NAWK BUT UNABLE TO GIVE THE STARTING POSITION SUCH AS 5 OR 10.
set tofind = $argv[1]
set string = $argv[2]
nawk -v TF=${tofind} -v STR=${string} 'BEGIN { print index(STR, TF) }'
PLEASE CAN ANYONE HELP ME OUT.
string1=dogs
string2 = animalsdogscatsdogs
now i need to find the starting position of string1 within string2 specified from a given position.
if d = [string1,string2]
then the value of d will be 8 as dogs starts from the 8th position in string2
now if d = [string1,string2,5]
then the value of d will be 8 since the starting position is from 5th position but still dogs start from position 8 in string2.
now if d = [string1,string2,10]
then the value of d will be 16 as the matching starts from position 10.
i need to atain the same functionality as described above usind awk or nawk or C SHELL.
I HAVE ATTAINED THE ABOVE FUNCTIONALITY USING NAWK BUT UNABLE TO GIVE THE STARTING POSITION SUCH AS 5 OR 10.
set tofind = $argv[1]
set string = $argv[2]
nawk -v TF=${tofind} -v STR=${string} 'BEGIN { print index(STR, TF) }'
PLEASE CAN ANYONE HELP ME OUT.