LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-12-2007, 05:49 PM   #1
xlordt
Member
 
Registered: Dec 2003
Distribution: Slackware
Posts: 32

Rep: Reputation: 15
comparing file


Is there away for me to compare 2 files with out using c/c++ python, java, etc.. maybe only using bash/awk? see the thing is that I need to loop through 2 files and compare each user with each file to see if they are there... if not than do something with the user? Now I prefer to do this in c++ but my job doesn't want me to do this because of the limited knowledge in c++ that stands in were I work at, so... ya, now If I have no other choice than I will create it in c++.

i.e:

file one
compare it with file two
loop trough the user names on both files and see if the user name
exist on both file.

Last edited by xlordt; 11-12-2007 at 06:00 PM.
 
Old 11-12-2007, 06:11 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
There are several tools for this sort of thing:
  • diff - compare files line by line
  • cmp - compare two files byte by byte
  • join - join lines of two files on a common field
Note that join requires that the two input files be sorted on the join fields.
 
Old 11-12-2007, 06:11 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
It depends on the layout of the file. If they're both just a list of user names, you could sort and use diff or sdiff to compare them. If the username is part of other data on each line, can you post a sample? Tools like cut can pull fields out of a line.
 
Old 11-12-2007, 06:37 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
See also comm, sdiff
 
Old 11-13-2007, 04:17 AM   #5
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Have a look at what kompare does. It is a nice graphical diff that can give a good overall view, depending on how many modifications have been done.
Usually I use tkdiff.
 
Old 11-19-2007, 03:32 AM   #6
avirup dasgupta
Member
 
Registered: Aug 2003
Distribution: Redhat , Fedora Core4, DSL,Solaris
Posts: 49

Rep: Reputation: 15
I use vimdiff (Vi advanced).
Also,Araxis Merge is a good tool which you can try out.
 
  


Reply



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 numbers sjcorp Programming 9 10-13-2007 03:27 PM
comparing drives warinthepocket Linux - General 7 09-23-2005 05:56 PM
Comparing distros dpeirce Linux - General 17 01-26-2005 11:08 PM
comparing music file pantera Programming 2 07-01-2004 02:57 AM
Comparing file sizes using a bash script. IanChristie Programming 5 12-19-2003 10:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:29 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
Open Source Consulting | Domain Registration