Find lines in events.log beginning with error:, ERROR:, Error:, or another case variation.
Ignore occurrences in the middle of a line.
Which command is appropriate?
grep -i ignores letter case while preserving the ^ anchor, so only a case-insensitive line-start prefix matches.
Detailed explanation
grep -v '^error:' events.logIncorrect. -v selects nonmatches and still treats case as distinct.
Incorrect. -v selects nonmatches and still treats case as distinct.
grep -n '^error:' events.logIncorrect. -n adds line numbers but does not change case sensitivity.
Incorrect. -n adds line numbers but does not change case sensitivity.
grep -F '^error:' events.logIncorrect. -F makes ^ literal rather than an anchor.
Incorrect. -F makes ^ literal rather than an anchor.
grep -i '^error:' events.logCorrect. -i ignores case and ^ keeps the match at the line start.
Correct. -i ignores case and ^ keeps the match at the line start.
Try it yourself
An example you can run in a temporary verification environment.
printf 'ERROR: disk\nError: net\nINFO: error: old\n' | grep -i '^error:'Expected result
ERROR: disk
Error: netKey points
- -i is case-insensitive
- ^ anchors the line start
- Middle-of-line matches are excluded
Notes
- Environment: GNU grep 3.x / C.UTF-8ロケール
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.