UNIX Programming, Certification, System Administration, Performance Tuning Reference Books
Replace Data in a File

You have a file that has the following line in it:
#define MM_VERSION_STR "3.0a4"

How to find a way to set up a script that, when run, will change the value of "3.0a4" to "3.0a5" and when it is run the next time to "3.0a6" and so on?

Try this:
awk '{ if ($2 ~ /MM_VERSION_STR/) printf "%s %s %s%d\"\n",$1,$2,substr($3,1,5),substr($3,6,1)+1 ; else print}' file
 

Or this:
awk '/MM_VERSION_STR/ { sub(/\"/,"",$3) ; $0 = sprintf("%s %s \"%s%d\"",$1,$2,substr($3,1,4),substr($3,5)+1) } ; {print > ARGV[1] }' file

...which can even count beyond 10 ;) - and it modifies the file in place.
 

Replace /MM_VERSION_STR/ in the above by:
$1 == "#define" && $2 == "MM_VERSION_STR"

in case MM_VERSION_STR appears elsewhere in the same file.

Quick Links:
Do you have a UNIX Question?

Unix Home: Unix System Administration Hints and Tips