The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 02-06-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
This might get you started.

I assume the config file and the changes file have the same format.
I also assume the changes file is a subset of the config file.

You could convert both of them to a different format.

e.g.

nawk '/\[.*\]/ { SECT=$1; next } { print SECT$0 }' configfile > tmpfile1
nawk '/\[.*\]/ { SECT=$1; next } { print SECT$0 }' changesfile > tmpfile2

Use info from tmpfile2 to make changes in tmpfile1.

When done convert tmpfile1 back to original format and use this file to replace the original config file.

running the command above on the example config file you provided would result in the following output:

tmpfile1:
[Section1]parm=value
[Section1]parm2=value
[Section1]parm3=value
[Section2]parm=value
[Section2]parm2=value
[Section2]parm3=value

Suppose your changes file looks like:

[Section1]
parm2=newvalue1

[Section2]
parm=newvalue2

Again using the command above the output would be:

tmpfile2:
[Section1]parm2=newvalue1
[Section2]parm=newvalue

Thsi puts the config and changes file in a similar format which makes it easy to make the necessary edits.

As mentioned, when the edits are done convert the format back.