From the false result, I can see the grep find line that also contain 531250 but not exact one. I've already invoke grep -w option but still showing the same prob. :wall:
From man grep (linux):Anchoring
The caret ^ and the dollar sign $ are meta-characters that respectively match the empty string at the beginning and end of a line.
So you need to use:
After I banged my head to wall several times I've come out with another solution by using awk
awk '{if ($1==531250) print}' file
will also give the output that i want.
But from my understanding about grep, option '-w' will only grep exact string right? In other word, apart from my ideal output the rest should have not apear right? Or am i missing something
The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character.
Similarly, it must be either at the end of the line or followed by a non-word constituent character.
Word-constituent characters are letters, digits, and the underscore.
So the extra lines match because your required string is at the end of the line and it is proceeded by a non-word constituent (the decimal point character).