Skip to content
Advertisement

Comparing two files and updating second file using bash and awk and sorting the second file

I have two files with two colums in each file that I want to compare the 1st column of both files. If the value of the 1st column in the first file does not exist in the second file, I then want to append to the second file the value in the 1st column of the first file, eg

firstFile.log

JavaScript

secondFile.log

JavaScript

After, secondFile.log should look like:

JavaScript

Note: Second file should be sorted by the first column after being updated.

Advertisement

Answer

Using awk and sort:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement