how to find substring position in a given string

Hello,

I have a string like
str = "14: Jan 29 13:27:12 : Processor----: [Thread:35]: Start of splitting file
"

from this, i have to find the position or location number starting for "Processor". I have to extract date from this entire string.

string which i will give will not have fixed length. sometimes the same string will be like " operation: [CLEANUP] parameter: [23185980] 15: Jan 29 13:51:37 : Processor---: [Thread:3]: task commit"

If i get the position of "Processor", i can go back and get the date always..

anybody pls help

echo "14: Jan 29 13:27:12 : Processor----: [Thread:35]: Start of splitting file" | sed "s/.*\([[:alpha:]]\{3\}\) \([0-9]*\) \([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*/\1 \2 \3/"

Shell-only solution:

set -- "${str% : Processor*}"; mydate="${1##*: }"

Example:

$ str="14: Jan 29 13:27:12 : Processor----: [Thread:35]: Start of splitting file"
$ set -- "${str% : Processor*}"; mydate="${1##*: }"; echo "$mydate"
Jan 29 13:27:12
$ str=" operation: [CLEANUP] parameter: [23185980] 15: Jan 29 13:51:37 : Processor---: [T
hread:3]: task commit"
$ set -- "${str% : Processor*}"; mydate="${1##*: }"; echo "$mydate"
Jan 29 13:51:37
1 Like