1

I have non-standard data, which I'd like to standardise

file:

d101 11001
e101 9665
f101 9663
d102 11002
e102 11003
f102 11004
g102 11005

desired output:

d101 11001
e101 12001
f101 12002
d102 11002
e102 11003
f102 11004
g102 11005

so the logic should be, if length of column2 = 4 it should replace it with incremental numbering of a provided series: in this case 1200 is series, & 1, 2, 3 .. are increments.

0

1 Answer 1

6
$ awk -v n=12000 'length($2)==4 {$2=++n} {print}' file
d101 11001
e101 12001
f101 12002
d102 11002
e102 11003
f102 11004
g102 11005

Note that we first increment n and then assign, to use the new value. If we wanted to start printing from 12000 we would use: $2=n++, first assign and then increase.

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.