Q:

how can I get the index of a character in a given concurrence which is repeated several times in a TEXT line using SHELL (BASH) script

I have a Text string like below
"/path/to/log/file/LOG_FILE.log.2013-10-02-15:2013-10-02 15:46:57.809 INFO  - TTT005|Receive|0000293|N~0000284~YOS~TTT005~  ~000~YC~|YOS     TYOS-YCUPDT1-H                  20131002154657669284YCARR TTT005   Y0TD04 |1|0150520106050|001|051052020603|003|015030010101502702060510520101|000||000||                                                               "

Here "|" is repeated several times within the string and I need to get the index of 4th occurrence of "|" character using shell-script (BASH) command.  I tried to find a way using grep command's options. 
Thanks. 

A:

grep can print the byte-offset; when used with -o it prints the byte-offset of the matching part. 
$ string="/path/to/log/file/LOG_FILE.log.2013-10-02-15:2013-10-02 15:46:57.809 INFO  - TTT005|Receive|0000293|N~0000284~YOS~TTT005~  ~000~YC~|YOS     TYOS-YCUPDT1-H                  20131002154657669284YCARR TTT005   Y0TD04 |1|0150520106050|001|051052020603|003|015030010101502702060510520101|000||000||"
$ grep -ob "[^|]*" <<< "${string}" | sed '5!d' | cut -d: -f1
132

Alternatively, without using grep:
$ newstring=$(echo "${string}" | cut -d\| -f5-)
$ echo $(( ${#string} - ${#newstring} ))
132

