I have a file which keeps count based on completion of a certain activity. I am using the following grep command to return a '1' in case the count is zero
grep -ic "0" abc_count.txt
Now the issue happens when the count is '10', '20' etc .. in these cases as well it returns a '1' because it sees a zero at the end of the count ..
Kindly, help me, how can I get a '1' using grep only when there is a zero count in abc_count.
Not sure if grep is the right tool for this request. Try to play with the -w and -o options. As you are dealing with numbers only, the -i option is pointless.
Please, try the following and see if your grep has the support for it:
grep "\<0\>" abc_count.txt
If you only see the expected results, then you can add the -c flag to return the count. The -i is not necessary because 0 will not make a difference for case insensitivity
If the file consists on a single line and that line only contains the number and the line-terminating <newline> character, a simple way to test would be:
grep -Fx 0 file
or for ancient versions of grep that don't have a -F option:
The -i (case insensitive search) is slower and does not make sense when searching for 0 .
The left/right boundaries in grep "\<0\>" are not known in HP-UX. grep -w 0 seems more portable.