0

I have several tables (tab separated) in which the first column is as follow:

MONTH
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00

I would like to replace those values by the actual month value, as follow:

MONTH
1
2
3
4
5
6
7
8
9
10
11
12
2

Using awk to replace the first field with the "line number-1" would work for your example case

$ awk 'BEGIN {FS="\t" ; OFS="\t" } NR>1 { $1=NR-1} { print}'

e.g.

$ cat x
MONTH   DATA
0.00    something
0.00    data
0.00    here
0.00    blah
0.00    blah
0.00    blah
0.00    blah
0.00    blah
0.00    blah
0.00    blah
0.00    blah
0.00    blah

$ awk 'BEGIN {FS="\t" ; OFS="\t" } NR>1 { $1=NR-1} { print}' x
MONTH   DATA
1       something
2       data
3       here
4       blah
5       blah
6       blah
7       blah
8       blah
9       blah
10      blah
11      blah
12      blah

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.