LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need some help on using diff command (https://www.linuxquestions.org/questions/linux-newbie-8/need-some-help-on-using-diff-command-856029/)

kingston 01-13-2011 02:51 AM

need some help on using diff command
 
hi all,

i have file1 and file2.
Quote:

File 1 contents are,
eingston
ewinston
eononono
edpdpdpd
Quote:

File 2 contents are,
edsdsdsd
ewinston
edpdpdpd
eingston
Here i want to compare these two files with diff command and need to take the common things in a separate file. File contents are 7 strings in length and everything will start with the character e.
File 3 contents should be
Quote:

ewinston
edpdpdpd
Please help me.

druuna 01-13-2011 02:59 AM

Hi,

Your examples have 3 entries that are in both files, not 2......

To use diff (or in this case comm) you need to have sorted in-files. If they are sorted then the following will show entries that are in both files: comm -12 file1 file2

Example run:
Code:

$ cat file1
edpdpdpd
eingston
eononono
ewinston

$ cat file2
edpdpdpd
edsdsdsd
eingston
ewinston

$ comm -12 file1 file2
edpdpdpd
eingston
ewinston

Hope this helps.

kingston 01-13-2011 03:10 AM

thanks drunna, it worked.
I didnt sort the files first. Now it works as i want. Thanks again, One more question.
In file1, eononono was remaining or we can say its not in file2. I want to take this in a separate file.
I need the same from file2. Please help me

druuna 01-13-2011 03:36 AM

Hi,

Files that are unique to file1: comm -23 file1 file2
Code:

$ comm -23 file1 file2
eononono

Files that are unique to file2: comm -13 file1 file2
Code:

$ comm -13 file1 file2
edsdsdsd

Hope this helps.

kingston 01-13-2011 04:28 AM

thanks man, you are great.
It worked well.

druuna 01-13-2011 04:37 AM

You're welcome :)


All times are GMT -5. The time now is 02:18 AM.