Print lines containing timeout from app.conf.
Prefix each matching line with its original file line number.
Which command is appropriate?
grep -n preserves matching lines and prefixes them with one-based source line numbers.
Detailed explanation
grep -n 'timeout' app.confCorrect. grep -n prefixes each matching line with its file line number.
Correct. -n retains each matching line and prefixes its one-based line number.
grep -c 'timeout' app.confIncorrect. -c prints only the number of matching lines.
Incorrect. -c returns only the number of matching lines.
grep -l 'timeout' app.confIncorrect. -l prints only filenames that contain a match.
Incorrect. -l returns the filename rather than the location within it.
grep -o 'timeout' app.confIncorrect. -o prints the matched text without the original line number.
Incorrect. -o prints the matching text, not the original line number.
Try it yourself
An example you can run in a temporary verification environment.
printf 'mode=prod\ntimeout=30\nretry=2\ntimeout=60\n' | grep -n 'timeout'Expected result
2:timeout=30
4:timeout=60Key points
- -n adds line numbers
- -c counts matching lines
- -l prints matching filenames
Notes
- Environment: GNU grep 3.x
- Use temporary files and harmless commands for pattern experiments.
- Regular-expression details should be checked against the target GNU implementation.
Foundation review
Place the condition
Line numbers support locating a setting; count and filename modes intentionally discard the line text or position.
Check the result
Place timeout on two known lines and compare the output of -n, -c, and -l.