Disclaimer: I am new to programming and scripting in general so please excuse the lack of technical terms
So i have two text file data sets that contain names listed:
First File | Second File
bob | bob
mark | mark
larry | bruce
tom | tom
I would like to run a script (pref python) that outputs the intersection lines in one text file and the different lines in another text file, ex:
matches.txt:
bob
mark
tom
differences.txt:
bruce
How would I accomplish this with Python? Or with a Unix command line, if it's easy enough?
sort | uniq is good, but comm might be even better. "man comm" for more information.
From the manual page:
EXAMPLES
comm -12 file1 file2
Print only lines present in both file1 and file2.
comm -3 file1 file2
Print lines in file1 not in file2, and vice versa.
You can also use the Python set type, but comm is easier.
Unix shell solution-:
# duplicate lines
sort text1.txt text2.txt | uniq -d
# unique lines
sort text1.txt text2.txt | uniq -u
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With