Extract lines equal to ready from status.txt regardless of case.
Exclude already and ready-now.
Which command is correct?
grep -i ignores case differences and -x requires the pattern to match the entire line. The options can be combined.
Detailed explanation
grep -ix 'ready' status.txtCorrect. It matches ready and READY as complete lines.
Correct. It matches ready and READY as complete lines.
grep -i 'ready' status.txtIncorrect. Without -x it also matches ready inside longer lines.
Incorrect. Without -x it also matches ready inside longer lines.
grep -x 'ready' status.txtIncorrect. Without -i it is case-sensitive.
Incorrect. Without -i it is case-sensitive.
grep -iv 'ready' status.txtIncorrect. -v selects lines that do not match ready.
Incorrect. -v selects lines that do not match ready.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s\n' ready READY already ready-now | grep -ix 'ready'Expected result
ready
READYKey points
- -i ignores case
- -x matches the whole line
- Options can be combined
Notes
- Environment: GNU grep 3.x / LC_ALL=C
- 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.