Number every logical line in notes.txt, including empty lines, without changing the content.
Which GNU nl command is appropriate?
nl -b a numbers all body lines, including blank lines. The default -b t numbers only non-empty lines.
Detailed explanation
nl notes.txtIncorrect. The default nl behavior numbers non-empty lines only.
Incorrect. The default nl behavior 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 -n ln notes.txtIncorrect. -n ln changes number alignment but not which lines are numbered.
Incorrect. -n ln changes number alignment but not which lines are numbered.
nl -b a notes.txtCorrect. -b a makes every body line, including blanks, a numbering target.
Correct. -b a makes every body line, including blanks, a numbering target.
Try it yourself
An example you can run in a temporary verification environment.
printf 'one\n\ntwo\n' | nl -b aExpected result
空行を含む3行すべてに連番Key points
- nl numbers lines
- -b a means all lines
- -b t means non-empty lines
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.