I’ve got two properties files and I’d like to replace key/value pairs in File A with any matching key/value entries in File B. File A will have more entries than File B – it’s not expected that the two files will have the exact same number of entries. Also, File B might have entries which are not included in File A.
As an example:
File A
"GB" = "United Kingdom";
"SE" = "Sweden";
"BR" = "Brazil";
"FR" = "France";
"ES" = "Spain";
"DE" = "Germany";
File B
"GB" = "Regno Unito";
"SE" = "Svezia";
"BR" = "Brasile";
"BR" = "Brasile";
"CL" = "Cile";
Desired Result
"GB" = "Regno Unito";
"SE" = "Svezia";
"BR" = "Brasile";
"FR" = "France";
"ES" = "Spain";
"DE" = "Germany";
"CL" = "Cile";
Is it possible to execute this search and replace using bash?
Thanks,
Sean
Here’s one way using
GNU awk:Results:
EDIT:
You can simply delete the array elements after a substitution has occurred. Then at the end of the script, print out what’s left:
Results: