Grep trouble in Bash

PH=(6H 0 0 JD 9S 0 KD 0)        #input from .txt file

In the above array, I am trying to get the computer to tell me at what indices the non-zeros are at.

I don't understand why this doesn't work...

grep -v -b "0" ph.txt > position.txt

Isn't grep -v supposed to show non matches in Bash ?

Could someone please clarify.

Cogiz

The grep -b option is not covered by the standards, and you haven't told us what OS or version of grep you're using. So grep -b and grep -v -b may do something completely different on your system from what it does on mine (which uses a grep from a BSD). With a BSD grep , the command:

grep -b 0 file

will print lines from file that contain the character 0 with each line preceded by the byte offset from the start of the file of the first byte on that line and a colon. And, the command:

grep -v -b 0 file

will print lines from file that do NOT contain the character 0 anywhere in that line with each line preceded by the byte offset from the start of the file of the first byte on that line and a colon.

In short, grep is an external command which operates on files and streams, it does not directly read from arrays.