Add numbers to the beginning of every line in a file

后端 未结 7 1677
暗喜
暗喜 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:22

    Here's a bash script that will do this also:

    #!/bin/bash
    counter=0
    filename=$1
    while read -r line
    do
      printf "%010d %s" $counter $line
      let counter=$counter+1
    done < "$filename"
    

提交回复
热议问题