如何使用shell脚本合并两个属性文件,例如: - 如果我有两个属性文件,如:
first.properties
/test/file="anish"
/test/version=3.0
second.properties
/test/author=nath
/test/version=2.0
Run Code Online (Sandbox Code Playgroud)
如果我将first.properties合并到second.properties上,那么常见的现有属性应该取自first.properties,所以我的输出应该看起来像
final.properties
/test/file="anish"
/test/version=3.0
/test/author=nath
Run Code Online (Sandbox Code Playgroud)
Gur*_*uru 18
其他方式:
$ awk -F= '!a[$1]++' first.properties second.properties
Run Code Online (Sandbox Code Playgroud)
此awk的输入是第一个文件的内容,后跟第二个文件.!a[$1]++仅打印特定键的第一个出现,因此删除第二个文件中的重复项.