On Fri, Jan 24, 2025 at 01:27:13PM +0000, Andreas BROCKMANN via Bug reports for GNU grep wrote: > Hi, > > The 1st command below correctly reports trailing spaces, for Unix and Windows > format files. > The 2nd one incorrectly reports all lines. > > grep -sHn -i " [[:cntrl:]]*$" *.vhd > grep -sHn -i "\s[[:cntrl:]]*$" *.vhd
As someone who just today made a similar mistake I would like to point out that the pattern does as intended because '*' matches *zero* or more occurrences of the preceding atom. So the second pattern matches any line that contains a *literal* 's' followed by zero or more control chars - you did not ask for perl regex and thus got basic POSIX regex instead; at least I *think* you want perl syntax given that '\s' is only valid in PCRE, IIRC. Also [:cntrl:] is not the correct char class for white space, why not [:space:] or [:blank:]?