Saturday, May 4, 2024
167
rated 0 times [  167] [ 0]  / answers: 1 / hits: 381770  / 3 Years ago, mon, august 23, 2021, 4:17:24

So basically what I want to do is compare two file by line by column 2. How could I accomplish this?



File_1.txt:



User1 US
User2 US
User3 US


File_2.txt:



User1 US
User2 US
User3 NG


Output_File:



User3 has changed

More From » command-line

 Answers
5

Look into the diff command. It's a good tool, and you can read all about it by typing man diff into your terminal.



The command you'll want to do is diff File_1.txt File_2.txt which will output the difference between the two and should look something like this:



enter image description here



A quick note on reading the output from the third command: The 'arrows' (< and >) refer to what the value of the line is in the left file (<) vs the right file (>), with the left file being the one you entered first on the command line, in this case File_1.txt



Additionally you might notice the 4th command is diff ... | tee Output_File this pipes the results from diff into a tee, which then puts that output into a file, so that you can save it for later if you don't want to view it all on the console right that second.


[#23494] Monday, August 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
serveeel

Total Points: 347
Total Questions: 106
Total Answers: 117

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
serveeel questions
;