使用Shell脚本合并两个属性文件 [英] Merge two properties file using shell scripts

查看:126
本文介绍了使用Shell脚本合并两个属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用shell脚本合并两个属性文件:-如果我有两个属性文件,例如

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

如果我将first.properties合并到second.properties上,则应该从first.properties中获取通用的现有属性,这样我的输出应类似于

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

推荐答案

另一种方式:

$ awk -F= '!a[$1]++' first.properties second.properties

此awk的输入是第一个文件的内容,后跟第二个文件. !a[$1]++仅打印特定键的第一次出现,因此删除了第二个文件中出现的重复项.

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.

这篇关于使用Shell脚本合并两个属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆