Bird
0
0

You run the command grep -c 'fail' report.txt but it returns 0 even though you know the file contains the word 'fail'. What is the most likely reason?

medium📝 Debug Q14 of 15
Linux CLI - Text Processing
You run the command grep -c 'fail' report.txt but it returns 0 even though you know the file contains the word 'fail'. What is the most likely reason?
AThe file report.txt is empty
BThe word 'fail' is in uppercase like 'FAIL' and grep is case-sensitive by default
CThe grep command syntax is incorrect
DThe file report.txt does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Understand grep -c behavior

    The -c option counts matching lines. If it returns 0, no exact matches were found.
  2. Step 2: Consider case sensitivity

    By default, grep is case-sensitive. If the file has 'FAIL' but you search 'fail', it won't match.
  3. Final Answer:

    The word 'fail' is in uppercase like 'FAIL' and grep is case-sensitive by default -> Option B
  4. Quick Check:

    grep is case-sensitive unless -i used [OK]
Quick Trick: Use -i to ignore case if matches return zero [OK]
Common Mistakes:
  • Assuming grep ignores case by default
  • Not checking file content carefully
  • Mistaking syntax errors for no matches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes