My projects have files web/.htaccess
Somewhere inside, each has a line like
SetEnv BUILD_ID 1443.303.0001016
I typically update these numeric fields (within a cron script) with:
grep "^SetEnv BUILD_ID " .htaccess && sed -i.bak -r 's/^(SetEnv BUILD_ID )([0-9]+)\.([0-9]+)\.(0*)([0-9]+)(.*)/printf "\1"$(date +%y%U.%j.)"%05d"$((\5+1))\6/ge' .htaccess
As you can see, the first two merely derive from the timestamp: yyWeekOfYear.DayOfYear.0001016
QUESTION The above sed correctly sets fields 1 and 2, but field 3 gets padded with five zeros, like so:
SetEnv BUILD_ID 1444.307.000001017
How can I increment this field 3 and update the whole line in-place in the file, using only modern awk/gawk , such that field 3 will have exactly 7 digits, padded by zeroes? Assume that none of my projects will ever have a minor version number that surpasses 10^7.
Or maybe this can be done using only date and bash ?
Similar in part to Perl / Awk / Sed - Find and Replace Number & auto-increment and Add leading zeroes to awk variable