๐Ÿ“š General & Other

Anchoring Makes the Difference Between Contains and Is

removes purely numeric lines. Every part of that pattern is doing work, and dropping any of it changes the meaning entirely.

grep -v '^[0-9]+$' removes purely numeric lines. Every part of that pattern is doing work, and dropping any of it changes the meaning entirely.

Both anchors are required

Without ^ and $, the pattern matches any line containing digits, and the filter becomes far broader than intended. This is the most common way a "purely numeric" filter quietly becomes an "any number" filter.

Whitespace defeats the anchors

A line of 42 does not match ^[0-9]+$ because of the spaces. It is still a purely numeric value for every practical purpose. Trim before filtering, or write the pattern to tolerate surrounding whitespace explicitly.

Numeric is broader than digits

Negative numbers, decimals, thousands separators and scientific notation are all numeric and none match ^[0-9]+$. If the goal is removing numeric values generally rather than digit strings specifically, the pattern needs to account for signs, separators and decimal points โ€” and at that point it is worth asking whether a numeric parse is clearer than a regex.

Try it: Remove Lines That Are Only Numbers on SeoWolf's Notepad.