LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2009, 01:00 PM   #1
caponewgp
LQ Newbie
 
Registered: Aug 2009
Posts: 14

Rep: Reputation: 0
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.
 
Old 09-17-2009, 01:18 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Please post a few lines from each file so we know what the format is.
 
Old 09-17-2009, 01:22 PM   #3
caponewgp
LQ Newbie
 
Registered: Aug 2009
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 09-17-2009, 02:17 PM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
This
Code:
diff -w final.txt <(cut -d: -f1 over1.txt)
produces this
Code:
3d2
< cconley
for me. Is that suitable?
 
Old 09-17-2009, 02:18 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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
 
Old 09-17-2009, 02:20 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by slakmagik View Post
Code:
diff -w final.txt <(cut -d: -f1 over1.txt)
Neat!

Last edited by catkin; 09-17-2009 at 02:21 PM. Reason: Neatening!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
comparing directories and files crazy8 Linux - Newbie 4 01-16-2008 10:33 AM
Comparing text files... jong357 Slackware 14 03-31-2007 04:29 PM
Comparing 2 Files for Duplicates Mr_H Linux - Newbie 5 11-09-2005 12:43 PM
comparing lots of files Frustin Linux - General 4 09-22-2005 02:54 PM
Comparing 2 Files xianzai Programming 2 05-23-2004 11:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration