Yes, grep is the standard tool for searching for text strings, so unless you really need to use something else, I doubt it's really worth the extra effort to come up with another solution.
Please use [code][/code]
tags around your code and data, to preserve formatting and to improve readability. Otherwise html rendering will remove all extra whitespace in front of and between words.
is a synonym for [[:alnum:]]
, a "word" character. What you wanted to use was \s
, which is a synonym for [[:space:]]
will only count the number of lines
matched. If there can be multiple matches on a line, then you may end up under-counting them. You can use grep's -o
option, which outputs every match on a separate line, and count the output with wc -l
, if this is an issue.
Finally, just to be perfectly clear, the [[:space:]]
character class must match an actual character. So the regex you have above will not match the string "gene" if it's at the beginning or end of the line.