Count literal text occurrences with grep -F -o -- 'text' file.txt | wc -l for a quick non-overlapping count, or use a browser counter when you need pasted text, overlap controls, or match positions.

Use the terminal route when the source already lives in a file or stream. Use the browser route when the source is on the clipboard and you need visible offsets or a defined overlap rule. “Online” describes the interface here, not an upload: the linked Count Occurrences performs matching, counting, and position collection inside the browser, and neither input is sent to Lizely.

The count occurrences command line vs online choice is mainly about source handling and output detail. Neither route is inherently more accurate; totals agree only when the literal string, case policy, overlap policy, and text boundaries are equivalent.

count occurrences command line vs online
Count Occurrences: Command Line vs Online

Choose by source, overlap, and output

A terminal utility fits scripts and pipelines because it can read a named file or standard input. A browser utility fits one-off inspection because the source can be pasted directly and the result can show where each match begins.

Consideration Command line Browser tool
Source Named files or standard input Pasted or typed text, up to 1,000,000 characters
Literal matching grep -F treats the query as a fixed string Literal only; punctuation has no regex syntax
Overlaps The basic grep pipeline is non-overlapping Explicit overlap option
Case handling Depends on command flags and the process locale Case-sensitive or case-insensitive, using English-locale lowercase comparison
Result Usually a count; a script can add offsets Full total plus the first 100 zero-based JavaScript offsets
Newlines Standard grep is line-oriented Can match across a newline when the search text contains one
Privacy The process runs locally Searching runs in the browser, and neither input is sent
Best fit Existing files, streams, and shell automation Clipboard text, overlap control, and position inspection

Treat this as a method comparison, not a claim that every command behaves like grep. Shells, editors, and scripting languages can add different quoting, locale, overlap, and encoding rules.

Count literal occurrences from a terminal

  1. Prepare the source and target. Place the source in a text file or route it into standard input. Copy the target exactly, including capitalization, spaces, and punctuation. Standard grep is line-oriented, so this workflow does not count a match spanning a newline.
  2. Run the literal-match pipeline. Use grep -F -o -- 'literal string' file.txt | wc -l on a grep implementation that supports -o. The -F flag makes the query a fixed string, -o prints each matching occurrence separately, and -- ends option parsing. Replace file.txt with a filename or use the command after a pipeline.
  3. Interpret the total correctly. The wc -l result counts the separate matches emitted by grep. Do not substitute grep -c: it counts matching lines, so multiple occurrences on one line still contribute only one matching line.
  4. Choose case behavior deliberately. For case-insensitive terminal matching, add -i before -o. Its behavior depends on the process locale, so record the environment when exact agreement with a browser result matters.
  5. Handle overlaps separately. The basic pipeline skips the full matched string, so it is non-overlapping. Use the browser’s explicit overlap option or a custom local script that advances one JavaScript string unit after a hit when shared starts must be counted.

Shell quoting and literal search are separate layers. Single quotes stop the shell from expanding most metacharacters before grep receives them; -F then tells grep not to interpret punctuation as a regular expression. A target containing a single quote needs valid shell-specific quoting.

Count pasted text in the browser

  1. Paste or type the source text. The source can contain spaces, tabs, line breaks, emoji, and ordinary Unicode, and it can be up to 1,000,000 characters.
  2. Enter the literal text to find. The search text can be up to 1,000 characters and may include spaces, tabs, pasted line breaks, emoji, or ordinary Unicode. An empty search is rejected.
  3. Set the matching options. Choose case-sensitive or case-insensitive matching, then decide whether matches may overlap. The tool does not silently switch between these interpretations.
  4. Count and inspect the result. Review the total and the first 100 zero-based starting positions. Editing either input or an option clears the previous output so a stale result cannot be mistaken for the current settings.

Matching, counting, and position collection happen locally in the browser, and neither the source nor the search text is sent to Lizely. The tool has no file-upload parser, so a file must be copied into the source field or handled through the terminal workflow. An exact search containing a newline can match across lines because the line breaks remain in the input.

The source text is not trimmed, line endings are not changed, whitespace is not collapsed, and duplicates are not removed. A search longer than the remaining source naturally returns zero; a zero result is valid and displays no positions.

Define literal, case, and overlap behavior

Literal matching

Count Occurrences does not compile a regular expression. A period matches a period, an asterisk matches an asterisk, and brackets have no special syntax, so no escaping is needed. It has no whole-word, fuzzy, stemming, or wildcard mode. For a count by word rather than a specified string, use Word Counter; for changing the matches, use Find and Replace Text.

Case sensitivity

Case-sensitive mode compares the entered strings exactly. Case-insensitive mode lowercases both the source and search input with English-locale lowercase behavior for comparison, while reported positions still refer to the original text. This is not a full linguistic collation engine: locale-specific equivalence, composed-to-decomposed Unicode normalization, accent folding, and script-specific case rules are not inferred.

Overlapping matches

Non-overlapping mode advances by the full length of the matched search string. Overlapping mode advances one JavaScript string unit after each match. For example, searching for aa in aaaa produces two starts at positions 0 and 2 in non-overlap mode, but three starts at positions 0, 1, and 2 in overlap mode. Non-overlap mode generally reflects the number of separate literal replacements, while overlap mode is useful for sequence analysis.

Interpret zero-based match positions

Positions are absolute, zero-based JavaScript string offsets from the start of the source, not line-and-column numbers and not user-perceived grapheme indexes. Most ordinary English characters consume one offset, while characters represented by surrogate pairs can consume two UTF-16 code units. An emoji before a later match can therefore shift the displayed position.

The position list is capped at 100 to keep a result with many matches usable, but the reported total is not truncated. Literal index lookup is the operation documented for MDN’s String.indexOf(). The case-insensitive comparison’s locale-aware lowercasing is documented for MDN’s String.prototype.toLocaleLowerCase().

If you reproduce offsets in a command-line script, JavaScript and Node use the same UTF-16 indexing model. A script based on another language’s character indexes may report different positions for surrogate pairs.

Resolve common result mismatches

  • Line count versus occurrence count: grep -c counts matching lines, while grep -F -o … | wc -l counts separate non-overlapping matches.
  • Overlap policy: The same text can legitimately produce different totals when one method counts shared starts and the other skips them.
  • Case rules: Terminal behavior may follow a process locale, whereas the browser tool uses its explicit case option and English-locale lowercase comparison.
  • Newline handling: Standard grep processes lines, while the browser tool can match search text that contains a newline.
  • Zero versus invalid: Zero means the search completed and found no match; an empty search string is rejected as ambiguous.

To compare results fairly, record the literal query, case mode, overlap mode, newline treatment, and position convention before running either route. That prevents a difference in matching rules from being mistaken for a difference in the source text.

If you're weighing options, Convert DOCX to TeX: Plain Text vs. LaTeX covers this in detail.

If you're weighing options, Convert \n to New Lines: Browser-Based API Alternative covers this in detail.