Scripting the process to edit a large file

Hi,

I need to make a script to edit a file. File is a large file in below format

Version: 2008120101
;$INCLUDE ./abc/xyz/Delhi
;$INCLUDE ./abc/xyz/London
$INCLUDE ./abc/xyz/New York

First line in the file is version number which is in year,month,date and serial number format. Each time when file is changed current month,date and serial number is changed.

Other 3 lines with INCLUDE statements are point of focus, where only one line will be active at a time without comment. I need to have a script which can change the version number each time when any change is being made and if input parameter is London then line with reference to London should be uncommented and other two should be commented. Same way if input parameter is New York then line with new york should be uncommented and other two should be commented and version number should change. I hope I could clarify the situation and my requirement. I am not a core Unix guy, so thought to take genious people's help. Thanks a lot in advance.

Regards.

city=$1
date=$( date +%Y%m%d )

awk -v date=$date -v city="$city" '
/^Version:/ {
  serial = substr( $2, 9 )
  olddate = substr( $2, 1, 8 )
  if ( date == olddate ) ++serial
  else serial = 1
  printf "Version: %d%02d\n", date, serial
  next
}
{ gsub(/^;/,"") }
index($0, city) { print; next }
{ print ";" $0 }
' "$FILE"

Thanks Cfajohnson for your reply..

Only thing that is not happening is Version.. Version is not incrementing each time when I am executing the script. it is only changing when date is changing, but serial number should also increment each time script is executed and also please suggest one more thing, I need to do the change the original file. What do you suggest, what is the best way to make the changes in original file apart from moving file with mv.

Please help me
Regards.

Did you copy the script exactly as I posted it? It works for me, including incrementing the version.

Do you get any error messages?

That is the best way to do it: send the output to a temporary file and mv or cp it to the original file.

Thanks Johnson for your earlier replies, but stucked again at one point. Script is running fine. Problem is if my db file is like:

version: yyyymmddrr
aaa
bbb
ccc
Include city London
ddd
eee
fff
Include city Sydney
.
.
more lines
.
..

now in this kind of db file, script is putting comment on all lines. but I need to put comment only on lines with "Include" but at the same time uncomment line matching city variable...

One last thing, I need to use this script in kind of a failover process in live production environment on large db files with around 1000 entries.

Thanks a lot in advance.

dt=`date '+%Y%m%d'`
t=`ls -l a.txt | awk '{print substr($8,0,index($8,":")-1)}'`
res=`echo $dt$t`
echo $res
echo "Pls input the city name"
read city
sed -n "
1 {
	s/.*/Version: $res/
	p
}
2,$ {
/$city/ !{
 s/^/Comment: /
 p
}
/$city/ {
	p
}
}" a.txt