0

I am currently on a crusade regarding this question. The edits that I made were reverted with a comment saying:

Please don't change your question after receiving answers. You can clarify, but not completely change so that the answers are no longer relevant. I have rolled back your edits to the last version that seems to match the answers you have been given. If you have more questions, please ask them separately, as new questions.

I am really angry with this. Please look again at my latest edit to the question. In my edit I ask

What would be some examples of the number of lines matching the pattern in a file and the number of matches in the same file, but counting each match but counting each match individually?

The existing answer mentions:

Example: The number of lines matching the pattern G in file:

and

Example: The number of matches in the same file, but counting each match individually:

So, the existing answer is still relevant. Also, I have asked this question on October 6th, 2023 when the UNIX site has been the today's featured site, so I cannot ask a new question now.

1 Answer 1

4

Thank you for posting here, this is the right way of bringing this sort of thing up.

Now, your original question, posted on Oct 6th asked:

The basic design philosophy of UNIX is to provide simple, powerful tools that can be combined to perform complex tasks. It features a command-line interface that allows users to interact with the system through a series of commands, rather than through a graphical user interface (GUI). How does the command-line interface work?

This was then completely changed on October 6th, the same day, to ask (after the question was edited to remove unnecessary detail):

Is there a way to count the number of occurrences of a pattern using the grep command?

Already, this is an entirely different question. One user posted an answer to this question on October 6th. This answer mentioned the idea of counting the matches individually. Perhaps this is what prompted your next edit, on October 9th, which changed the question to:

The standard usage of grep is to return lines that match a pattern. If a line can contain several matches of the pattern, how can I count count each match individually?

Again, this is a different question. But still close enough to the original to be a reasonable change. However, next, on November 6th, yesterday, you changed the question to ask for examples:

Examples of the number of lines matching the pattern in a file and the number of matches in the same file, but counting each match individually

Courtsey link: Count total number of occurrences using

grep

grep's -o will only output the matches, ignoring lines; wc can count them:

grep -o 'needle' file | wc -l

This will also match 'needles' or 'multineedle'.

To match only single words use one of the following commands:

grep -ow 'needle' file | wc -l grep -o '\bneedle\b' file | wc -l grep -o '' file | wc -l

The linked answer states that grep's -o will only output the matches, ignoring the lines, and wc can count them. The standard usage of grep is to return lines that match a pattern.

What would be some examples of the number of lines matching the pattern in a file and the number of matches in the same file, but counting each match individually?

This is now a completely different question: you are no longer asking how to count matches or even how to count individual matches, you know how to do that, and even mention it in the question, and are now asking for examples. This is a completely different question and renders al existing answers obsolete.

So, if this is what you want to ask, please post a new question, you can always link back to this one, and ask that there. That said, I don't really think this would be on topic here. It is a very open-ended question that cannot have one, correct answer, so it would come under the "too broad" off-topic reason. Asking for examples means that every answer will be equally valid. See https://unix.stackexchange.com/help/dont-ask:

To prevent your question from being flagged and possibly removed, avoid asking subjective questions where …

  • every answer is equally valid: “What’s your favorite ______?”

[. . .]

So, in summary, while editing your question to clarify it is absolutely welcome, please don't make edits that change the question too much from the original version if you already have answers since that makes the answers obsolete.


On a separate note, I don't understand what you mean by:

I have asked this question on October 6th, 2023 when the UNIX site has been the today's featured site, so I cannot ask a new question now.

Featured site? Featured where? Do you mean the "featured site" in the sidebar of https://stackexchange.com/? That... really doesn't mean anything other than that's the site some algorithm picked to display. It is only a way to advertise a given site, it doesn't change anything.

In any case, you can always ask a new question! There is no need for this site to be "featured" whatever that means, the site is always open and you are always welcome to ask a new question.

2
  • Yes, I am talking about the "featured site" in the sidebar of stackexchange.com.
    – Arunabh
    Commented Nov 7, 2023 at 17:07
  • 3
    Oh. I didn't even know that existed, @ArunabhBhattacharya, I only found it because you mentioned it. It really doesn't mean anything at all. It doesn't make any difference to the site, there's nothing special about that day.
    – terdon Mod
    Commented Nov 7, 2023 at 17:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .