Sample Header Ad - 728x90

grep -c gives a different count to grep | wc -l

2 votes
1 answer
133 views
I expected these two commands to give the same count of how many lines in my file contain a letter:
grep -c '[A-Z,a-z]' archive_for_TO.050225
11873
grep '[A-Z,a-z]' archive_for_TO.050225 | wc -l
11859
The file is too large to post here, but I wonder if there are some common cases/explanations why the second command apparently finds 14 fewer matching lines than the first. For example, does it indicate that the text file has some inconsistencies in how lines are separated (character return or line feed or both)?
Asked by Tim Osborn (31 rep)
Feb 13, 2025, 12:22 PM
Last activity: Mar 11, 2025, 02:01 PM