I would like to simply keep up-to-date records in file A given file B using bash on Linux.
Both A and B files have same structure.
There is a record on each line of file consists of public-key and comment separated by space. Comment is a composition of user@hostname and is unique in file.
Example:
B file
xxxxxx user1@hostname1
yyyyyy user2@hostname2
wwwwww user3@hostname3
A file
yxxxxx user1@hostname1
zzzzzz user4@hostname4
yyyyyy user2@hostname2
Which should result into:
A file
xxxxx user1@hostname1
zzzzz user4@hostname4
yyyyy user2@hostname2
wwwww user3@hostname3
I know I can read B file line by line and check whether file A contains a record by comment. If not append record. If yes, check whether to update. However it evolves a multiple lines of code in bash script.
Can it be done simpler?