Edit a config file using shell script

I need to edit a config file using shell script. i.e., Search with the 'key' string and edit the 'value'.

For eg: below is what I have in the config file "configfile.cfg".

Key1=OldValue1
Key2=OldValue2

I want to search for "Key1" and change "OldValue1" to "NewValue1"

Thanks for your help.

If you want to replace one key in one file you can do it with vi or is this homework?

Regards

I want to do it in around 100 files - using shell script or a command. Not manually.

hope this hepls you

sed -e 's/\(key1\=\)\(Old\)\(value1\)/\1New\2/g' filename

please iterate this in you shell programs for the key1 values and old value for each file.

Edit: had that tab open for a while - chappidi_pradee gave a better solution

Thanks pradee.

Will this work for the below cases?

#This is a comment. YesNoFlag = No means it will not print
YesNoFlag = No

And I need to change No to Yes

i think the script that i posted will not work for the example that you mentioend becasue there should not be any spaces between the equal to sign (=).

what about the 'Key' part? I think the 'No' in the key (YesNoFlag) also will get replaced right? And again it will not skip the comment lines, correct?