Search code examples
batch-filefindstr

Need a way to obtain total instances after finding using FINDSTR


So this is what I have so far and it works finding the specified string but I need it to echo the total number of times it's found.

FINDSTR /C:"\"MA\"" %FN%

Thanks in advance.


Solution

  • findstr has no counter, but find has (but has no regex).

    Also findstr /c: searches for \"MA\" literally. You should add /R (assuming you search for "MA"). You can combine both commands to your needs:

    FINDSTR /R /C:"\"MA\"" %FN% | find /c /v ""