finding common between two files
I need to print common lines between two files using "FOR LOOP" and "IF ELSE" command.
#vi File1 apple orange mango grapes #vi File2 apple orange strawberry banana Output: apple orange Please Help Me Out Of This Quest..! |
Hi,
Welcome to LQ! Code:
# comm file1 file2 |
Output:
apple orange banana mango grapes strawberry Hi thanks a lot for your reply...!! I used the command which you replied me but i got the above output..!! |
Which OS are you using?
And I checked it on my test machine. It gives me this output - Code:
[root@testmachine ~]# comm file1 file2 Code:
[root@testmachine ~]# comm --nocheck-order file1 file2 |
Here is the correct output. But the contents of the file should be in sorted order. Or you can first sort the contents of the file.
I have file1 and file2. Code:
[root@testmachine ~]# cat file1 Code:
[root@testmachine ~]# cat file2 Code:
[root@testmachine ~]# comm --nocheck-order file1 file2 |
Hi
I just mis-understand the command.. Now am getting the correct output.
Thank You so much Satyaveer Arya..!! |
1) This sounds quite a bit like homework to me. If so, please read the LQ rule regarding homework.
2) Please use ***[code][/code] tags*** around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. 3) Please supply more detail and context. Do you actually NEED to use for/if for this? What have you tried to do so far? Also be sure to add any important information about the environment. Are you using bash or a different shell, for example? 4) Never just say it "didn't work". Always post the exact code you used and the error messages you got. 5) Have you tried searching the forums yet? This is the kind of question that comes up with frustrating regularity. |
Thanks for your information David the H.
|
All times are GMT -5. The time now is 12:58 PM. |