I am working with OpenWRT config file. One of my config file is like,
File 1:
config wifi1
option enable '1'
option status ''
option ssid ''
File 2:
config wifi1
option enable '1'
option status ''
option ssid 'Primary5G'
option password '12345678'
File1 is my default file, File2 is runtime generated file. In case if we add more parameters to File1. For example,
File1 Modified,
config wifi1
option enable '1'
option status ''
option ssid ''
option wps '1'
I need to merge these files, copy the missing parameters content into File2, without overwriting the existing modified parameters. So the File2 should be like,
config wifi1
option enable '1'
option status ''
option ssid 'Primary5G'
option password '12345678'
option wps '1'
I need to do this shell script for merging the content. I tried to use diff and patch for obtaining the output required.
I tried with below commands,
diff file1 file2 > diffs
This diffs has all the modifications, which I don't require. If this could have worked, thought of applying this patch using,
patch -i diffs file2
But it is overwriting the existing parameters as well. And I can't use pattern because we have have multiple parameters going forward. Any help?
Sample file will be like,
config wifi-device 'radio0'
option type 'mac80211'
option channel '104'
option hwmode '11a'
option path 'pci0000:00/0000:00:00.0'
option htmode 'HT20'
option country 'DE'
config wifi-iface
option device 'radio0'
option network 'lan'
option mode 'ap'
option ssid 'OpenWrt'
option encryption 'none'