LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash script to output only differences in two files (https://www.linuxquestions.org/questions/programming-9/bash-script-to-output-only-differences-in-two-files-252494/)

czarherr 11-08-2004 01:43 PM

bash script to output only differences in two files
 
I am writing a script that will output an ls command to a file, and compare that file to one that will already exist. I need the script to compare the two files, and output only the lines in the ls that don't appear in the preexisting file. For example, it will ls the programs in /bin, and redirect it to the bindirectory file it will create. It will then check the bindirectory file against one I will have made prior to this, binbase, and take the differences in the two, and output it to the cutdirectories.tmp file. I just need to know how to get only the differing lines.

gmartin 11-08-2004 01:49 PM

Take a look at the diff command.

Hko 11-08-2004 01:54 PM

Try something like:
Code:

diff bindirectory binbase >cutdirectories.tmp

dannyp 11-08-2004 06:13 PM

You could use the comm command

Code:

comm -12 file1 file2

ror 11-08-2004 06:25 PM

I thought diff was a better comm?


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