[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A out-of-expectation output when use both -o and -c option
From: |
larmbr zhan |
Subject: |
A out-of-expectation output when use both -o and -c option |
Date: |
Sat, 2 Feb 2013 20:45:06 +0800 |
Hi, all
When use --only-matching with -c, grep gives a
counter-intuitive output on this input:
$ cat poc.txt
alan cox is a guy.
cox versus cox
cox cool
$ grep -o -c "cox" poc.txt
What I suppose it to give is 5, but actually 3.
I checked the manual and found "-c" reports
the number of matching lines. Grep just behaves
correctly :-)
I also checked the POSIX docs and found that POSIX
mandates the '-c' option , but not the '-o' option.
So for the sake of compliance with the standard, it *does*
have bias in favor of -c, and neglects the -o.
However,I think what an utility behaves should not
surprises its user. We should not blame user that why
don't you read the f*cking manual first to make it work
correctly.
Naturally, counting the number of exact matching parts
is a reasonable and quite useful feature.
Since we shouldn't change the semantics of '-c". what should
it do is just give a waring when user use -c and -o.
and should clarify it in doc, just as what grep does when -C(context) and
-o are used together.
I don't know if this is a feasible way; and if it is , I will submit a patch
for this.
---
Larmbr Zhan
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- A out-of-expectation output when use both -o and -c option,
larmbr zhan <=