Edward
Edward

Reputation: 343

How to add number to beginning of each line?

This is what I normally use to add numbers to the beginning of each line:

awk '{ print FNR " " $0 }' file

However, what I need to do is start the number at 1000001. Is there a way to start with a specific number like this instead of having to use line numbers?

Upvotes: 2

Views: 108

Answers (3)

Ed Morton
Ed Morton

Reputation: 203635

$ seq 5 | awk -v n=1000000 '{print ++n, $0}'
1000001 1
1000002 2
1000003 3
1000004 4
1000005 5

$ seq 5 | awk -v n=30 '{print ++n, $0}'
31 1
32 2
33 3
34 4
35 5

Upvotes: 1

karakfa
karakfa

Reputation: 67507

there is a special command for this nl

nl -v1000001 file

Upvotes: 3

anubhava
anubhava

Reputation: 785196

You can just add 1000001 to FNR (or NR):

awk '{ print (1000001 + FNR), $0 }' file

Upvotes: 1

Related Questions