Add numbers to the beginning of every line in a file

后端 未结 7 1703
暗喜
暗喜 2020-12-01 02:44

How can I add numbers to the beginning of every line in a file?

E.g.:

This is
the text
from the file.

Becomes:

000000001 This is
000         


        
7条回答
  •  生来不讨喜
    2020-12-01 03:14

    Don't use cat or any other tool which is not designed to do that. Use the program:

    nl - number lines of files

    Example:

    nl --number-format=rz --number-width=9 foobar
    

    Because nl is made for it ;-)

提交回复
热议问题