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*

7
  • 1
    what if there are no spaces, i.e. the field name is surrounded by quotes? e.g. "field" Commented Sep 19, 2010 at 16:42
  • @mythz: Then you replace the quotes with newlines with tr. I'll update the answer. Commented Sep 19, 2010 at 16:45
  • 2
    This answer is incorrect in many ways. It is vague: you should explain how to come up with a tr command that does the job instead of suggesting examples that will never work in all situations. It will also match words that contain the word you are looking for. The grep -o '\<WORD\>' | wc -l solution is far superior. Commented Apr 9, 2011 at 2:28
  • 1
    @Sam, the question leaves it kind of open, if a searched word should be searched like 'WORD' or '\<WORD\>' - you can read it both ways. Even if you read it the 2nd way and only in the 2nd way, then my answer would be only incorrect in 1 one way. ;) And the 'grep -o' solution is only superior, if it supports the -o option - which is not specified by POSIX ... Well, I don't think so that the use of tr is that exotic to call it vague ... Commented May 6, 2011 at 21:01
  • 1
    @Kusalananda, well, it's still an occurrence. But if you don't want to count such substring matches then please read the last paragraph of my answer and my previous comment here. Commented Apr 4, 2019 at 9:10