last day (16 days later) » 

8:35 PM
1
A: How to diff and patch new lines only

Rico ChenThis is possible with awk. With /* diff.awk */ BEGIN {FS="="} FILENAME==ARGV[1] && $1 !~ /^[#\[]/ { a[$1]=$2 } FILENAME==ARGV[2] { b[$1]=$2 } END { for(i in b) { for(j in a) { if(!b[j]) { c[j]=a[j] } } c[i]=b[i] } ...

 
First of all thanks for your input. It is doing the difference without order and from both files. Also, can we ignore the lines starting with "#" and "[" from comparison. what we need is only newly added lines of conf1 file into conf2 in an ordered manner.
Below 2 commands does the job. But, looking for alternatives without git client installed. git diff --diff-filter=a conf2 conf1|grep -E ^\+ >temp patch -o conf2 -i temp
 
Although the solution you found might work for you since you have the git commit history to play with but it can't be used in more general situations. Also I am not seeing order extremely important for config files and sorting them only makes cosmetics differences. For skipping lines starting with '#' and '[' please see the updated answer.
 
Would like to add a point on your comment. Neither I have git commit history nor git is my source control here. Seems like, it works on any files.
 
Your are right, thanks for sharing this interesting solution.
 
@ Rico Chen Appreciate your prompt response. only 2 gaps I could see. 1. Order is very important for us. 2. for empty lines it is adding "=", this is minor and can be handled by removing lines starting with =.
 
8:35 PM
Also keep in mind my solution might not work any more due to your [app] addition to your examples after your original post. The awk solution I gave assume that you have flat (simple) config file structure.
I think you might need a parser for your need.
 
Hi Chen,
Thanks for providing me solution. Appreciate your help.
 
No problem at all.
 
Order is very important for us, because we have [app1] [app2] [app3] and under that we have configs specific to that app. We can't combine the parameters. As we are customer facing, it will look awkward.
 
I understand. My guess is the config is part of an application that's not shell script?
If so I would suggest you look into more specialized parsers instead the shell commands we discussed.
The structure tells me that you will have sections in the configs, not just key/value pairs.
You might want to look into php.net/manual/en/function.parse-ini-file.php as your config file is very similar to a php ini file.
or github.com/shangerxin/config-ini if you are a fan of nodejs (I am)
Disclaimer - I haven't tried either of them
Here's a post on parsing ini files with nodejs thisdavej.com/…
 
I just verified, we can't use php and nodejs.
seems like we have python
 
8:49 PM
seems the last one can even do merge for you
 
Thank you Chen. I will take a look at it.
 
no problem, here's an example using it github.com/pixelb/crudini/issues/63
 
seems like it's gonna work. I have to copy this script, understand and test.
Thanks again.
Taking leave. Have a great day ahead.
 

  last day (16 days later) »