10

たとえば、シェルスクリプトを使用して2つのプロパティファイルをマージする方法: - 次のような2つのプロパティファイルがある場合

first.properties
/test/file="anish"
/test/version=3.0

second.properties
/test/author=nath
/test/version=2.0

first.properties を second.properties にマージすると、共通の既存のプロパティが first.properties から取得されるため、出力は次のようになります

final.properties
/test/file="anish"
/test/version=3.0
/test/author=nath
4

2 に答える 2

20

別の方法:

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

この awk への入力は、最初のファイルの内容とそれに続く 2 番目のファイルです。!a[$1]++特定のキーの最初の出現のみを出力するため、2 番目のファイルに表示される重複が削除されます。

于 2012-12-24T06:00:48.627 に答える
2
$ cat first.properties second.properties | awk -F= '!($1 in settings) {settings[$1] = $2; print}'
/test/file="anish"
/test/version=3.0
/test/author=nath
于 2012-12-24T05:58:41.260 に答える