LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   which lines are identical in the two files (https://www.linuxquestions.org/questions/linux-newbie-8/which-lines-are-identical-in-the-two-files-4175581270/)

torito 06-02-2016 09:03 AM

which lines are identical in the two files
 
Hi everyone!

I am trying to write a command to find out which lines are identical in the two files.
I come up with grep -f file1 file2 > newfile

The problem is when I open newfile, it is empty. There is nothing there.

Any suggestions, please?

Thank you very much!

weibullguy 06-02-2016 09:26 AM

Your command works for me. Maybe file1 and file2 have no lines in common.

torito 06-02-2016 09:31 AM

Ummm.... interesting. I typed using vi an exact line in both files, but that line is not shown in the newfile.

ntubski 06-02-2016 09:45 AM

Does file1 have any special characters in it? (e.g. ".", "*", "\", "[", "]", etc)

You should use -F (fixed strings, rather then regexps)

Code:

grep -Ff file1 file2 > newfile

grail 06-02-2016 09:52 AM

You could also try looking at the comm command.

torito 06-02-2016 10:08 AM

Thank you everyone!!!!!!!!!!!!!!!!!!!


All times are GMT -5. The time now is 09:50 PM.