
200 行を追加する必要があるファイルがありますが、自動的に番号を付け直す方法を知りたいです。ファイルの構造は次のとおりです。
列1\t列2\tdb4444\t列4\t列5\t列6\t列7\t列8\t列9\t列10\n
列1\t列2\tdb4445\t列4\t列5\t列6\t列7\t列8\t列9\t列10\n
列1\t列2\tdb4446\t列4\t列5\t列6\t列7\t列8\t列9\t列10\n
...
ここで、\t はタブ、db は数字の前に記述され、他の列は col で表され、最後に \n は改行です。この場合、counter は 3 番目の列にあり、db に関連付けられている必要があります。最初の行は次の数字から始まる必要があります。これは bash コマンドでもかまいません。
ご清聴ありがとうございました!
答え1
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