How to add a counter starting from a number other than 1?

0

I have a file where I need to add 200 more lines, but I'd like to know how to renumber them automatically. The file has the following structure:

col1\tcol2\tdb4444\tcol4\tcol5\tcol6\tcol7\tcol8\tcol9\tcol10\n

col1\tcol2\tdb4445\tcol4\tcol5\tcol6\tcol7\tcol8\tcol9\tcol10\n

col1\tcol2\tdb4446\tcol4\tcol5\tcol6\tcol7\tcol8\tcol9\tcol10\n

...

Where \t is the tab, db is written before the number, the other columns are represented by col and finally \n is the line break, in this case, counter must be in the 3rd column and associated with db. The first line should start from the next number. It can be a bash command.

Thank you for your attention!

Primo

Posted 2019-07-02T18:35:14.553

Reputation: 11

1I do not know where to start trying. – Primo – 2019-07-02T18:50:53.843

Yes, I know there are not many, but these 200 are just the first of many others. – Primo – 2019-07-02T19:11:30.063

Answers

0

lastline=$( tail -n 1 "$filename" )           # get last line of file
IFS=$'\t' read -r a b db_id c <<<"$lastline"  # extract the 3rd field
db_id=${db_id#db}                             # remove the "db" prefix
next_id=$(( db_id + 1 ))                      # add 1 to get the next id

glenn jackman

Posted 2019-07-02T18:35:14.553

Reputation: 18 546