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. grep -n prefixes each matching line with its file line number.
grep -c 'timeout' app.confIncorrect. -c prints only the number of matching lines.
Incorrect. -c prints only the number of matching lines.
grep -l 'timeout' app.confIncorrect. -l prints only filenames that contain a match.
Incorrect. -l prints only filenames that contain a match.
grep -o 'timeout' app.confIncorrect. -o prints the matched text without the original line number.
Incorrect. -o prints the matched text without 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
- 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.