How to merge two properties file, using shell scripts for example : - if i have two properties file like
first.properties
/test/file="anish"
/test/version=3.0
second.properties
/test/author=nath
/test/version=2.0
if i merge first.properties over second.properties then common existing property should taken from the first.properties so my output should look like
final.properties
/test/file="anish"
/test/version=3.0
/test/author=nath
Another way:
$ awk -F= '!a[$1]++' first.properties second.properties
The input to this awk is the content of first file followed by second file. !a[$1]++
prints only the first occurence of a particular key, hence removing duplicates apparing in the 2nd file.
$ cat first.properties second.properties | awk -F= '!($1 in settings) {settings[$1] = $2; print}'
/test/file="anish"
/test/version=3.0
/test/author=nath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With