notes.txt contains text and blank lines.
Display consecutive line numbers for every line, including blank lines.
Which command is appropriate?
nl numbers input lines. The body style -b a includes blank lines; the default -b t numbers only non-empty lines.
Detailed explanation
nl notes.txtIncorrect. The default body style numbers non-empty lines only.
Incorrect. The default body style numbers non-empty lines only.
nl -b t notes.txtIncorrect. -b t explicitly selects non-empty text lines.
Incorrect. -b t explicitly selects non-empty text lines.
nl -b a notes.txtCorrect. -b a numbers both text and blank lines.
Correct. -b a numbers both text and blank lines.
wc -l notes.txtIncorrect. wc -l returns a count rather than displaying each line with a number.
Incorrect. wc -l returns a count rather than displaying each line with a number.
Try it yourself
An example you can run in a temporary verification environment.
printf 'one
two
' | nl -b aExpected result
1 one
2
3 two
※行番号欄の幅は既定値Key points
- nl adds line numbers
- -b a includes every line
- Blank lines are excluded by the default
Notes
- Environment: GNU coreutils 9.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.