Getting the index of a string in a string

view story

http://www.unix.com – I have a variable Code: $line= Some text with ERR message I want to get the value of the index of ERR and assign to a variable say $index I expect the output Code: echo $index 16 I tried to use match function of awk, but unable to pass a string as input instead of a file Also tried the following code Code: index=awk '{for(i=1;i<=NF;i++) if($1~/^ERR/){print i}'<$line (HowTos)