I have two files and I need to know the difference between each line. This will extend to thousand lines and manual works is really not really an option.
sample:
First File Second File
allan entry1 entry2 entry3 allan entry1 entry3
bob entry1 entry2 entry3 entry4 bob entry1 entry4
I want to output the difference only. Sample output:
allan entry2
bob entry2 entry3
I know that simple grep will not work here. UNIX is new to me and this is the only way i think this can be done.
First File
allan entry1 entry2 entry3
bob entry1 entry2 entry3 entry4
Second File
allan entry1 entry3
bob entry1 entry4
Output:
allan entry2
bob entry2 entry3
Using diff and comm doesnt give me the result that I want. The result should only be the name and the the entry that cant be found on the second file. In my example, allan will have entry 2 since it is not on the second file.
Are the two files guaranteed to have the same number of lines? So if a bob line is in one file it is also in the other? Are the records in the same sequence in both files?
If you have Python and know the language, here's an alternative:
#!/usr/bin/python
for line in open("file2"):
line = line.strip() #get rid of newlines
name,entry = line.split(' ',1)
for lin in open("file1"):
lin = lin.strip()
if lin.startswith(name):
for e in entry.split():
lin = lin.replace(e , "")
print "Output: ", lin
output:
/test # ./test.py
Output: allan entry2
Output: bob entry2 entry3