LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Comparing two files problem (https://www.linuxquestions.org/questions/linux-newbie-8/comparing-two-files-problem-755973/)

caponewgp 09-17-2009 01:00 PM

Comparing two files problem
 
Ok im trying to compare two files and I only want to display the user names that are in the first file and not the second.

So I have one file named
final.txt (which contains every user name and only the user names in a list no other information)

Then I have another file Over1.txt (which only contains certain users that have different permissions This file is also setup differently with the user name and some information about the user after the user name.

I need a way to compare final.txt to over1.txt so that I will only display the names that are in final.txt but not Over1.txt

Ive tried using diff and comm but just cant seem to get it two work correctly. Im not sure if im missing a option or what.

catkin 09-17-2009 01:18 PM

Please post a few lines from each file so we know what the format is.

caponewgp 09-17-2009 01:22 PM

final.txt looks like this
bbenson
bburt
cconley
and so on with names

then the other file over1.txt
bbenson : Bill Benson : /home/BillBenson: /bin/bash
bburt : Bill Burt : /home/BillBurt: /bin/bash
and so one with all the users

slakmagik 09-17-2009 02:17 PM

This
Code:

diff -w final.txt <(cut -d: -f1 over1.txt)
produces this
Code:

3d2
< cconley

for me. Is that suitable?

catkin 09-17-2009 02:18 PM

Does this work? final.txt may already be "cleaned" in which case no need for that step
Code:

cat over1.txt | awk '{ print $1 }' | sort | uniq > over1.cleaned.txt
cat final.txt | sort | uniq > final.cleaned.txt
comm -3 final.cleaned.txt over1.cleaned.txt


catkin 09-17-2009 02:20 PM

Quote:

Originally Posted by slakmagik (Post 3687414)
Code:

diff -w final.txt <(cut -d: -f1 over1.txt)

Neat! :)


All times are GMT -5. The time now is 12:52 PM.