A pipeline connects one command's output to the next command's input. Order matters.
Filter unwanted records before counting, and remove duplicates before counting distinct work items. wc -l counts newline-delimited rows, not unique identifiers or logical events. Use grep -v for an exclusion only when it matches the rows the request excludes.
Inspect an intermediate stream when the final count is surprising; a short number can hide a wrong selection. Read a pipeline from left to right and name the records present after each stage. A row filter changes membership; sort changes order; uniq removes neighboring repeats; wc reduces the stream to a count. Running the first two stages on their own exposes a missing filter before the final count hides the individual records.