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.
nl -b t notes.txtIncorrect. -b t explicitly selects non-empty text lines.
nl -n ln notes.txtIncorrect. -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.
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 / 標準入力
- Use small, disposable text streams when testing filters.
- Locale, encoding, and GNU/POSIX implementation details can affect edge cases.
Foundation review
Place the operation
The body-numbering mode controls whether empty lines receive numbers.
Check the side effect
Create a test input with a blank line between two records.