Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • I'm not sure you're actually checking it's only appearing once? All you're looking for there is that either one of those words exist at least once. Commented Jul 11, 2018 at 2:29
  • 1
    This should be the accepted answer. No need to use wc -l, grep has a built-in option to count things, and it is even named as obvious as -c for “count”! Commented Aug 6, 2020 at 20:03
  • 8
    @rugk You completely missed the first sentence in OP's post, which explicitly explains that -c only counts one occurrence per line. If a string occurs 1000 times on the same line, grep -c will still only count it as one. This answer makes no sense at all for this question. Commented Aug 6, 2021 at 21:52
  • The whole point of the question is exactly that the -c option does not work. Commented Nov 4, 2023 at 13:58