You are not logged in.

#1 2010-08-27 15:01:25

lifeafter2am
Member
From: 127.0.0.1
Registered: 2009-06-10
Posts: 1,332

[solved] Difference Between Two Files

Okay, so I have been trying to use diff to do this, but I am failing, as this isn't code I am looking at (and I'm not really a programmer).

I have two text files with a single line per entry (which is a userid).  I need to be able to compare the two files, and output only the userid's that don't show up in one of the files.

Example:

File 1                File 2
a                      a
b                      s
c                      c
d                      t

So the output would be simply s and t. 

Can I use diff to do this?  If not, can someone maybe hack up a quick Perl script or something?  I know there has to be a better way than going through a 2000+ userid file by hand.

Thanks!

Last edited by lifeafter2am (2010-08-27 16:19:53)


#binarii @ irc.binarii.net
Matrix Server: https://matrix.binarii.net
-------------
Allan -> ArchBang is not supported because it is stupid.

Offline

#2 2010-08-27 15:03:35

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: [solved] Difference Between Two Files

diff will only tell you the differences between files. What you want is something custom. So you might just have to create a script to do it.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2010-08-27 15:04:56

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [solved] Difference Between Two Files

diff is the wrong tool to use here. Try comm(1).

Offline

#4 2010-08-27 15:07:53

lagagnon
Member
From: an Island in the Pacific...
Registered: 2009-12-10
Posts: 1,087
Website

Re: [solved] Difference Between Two Files

I'm not sure but perhaps what might work for you is the command "comm". See "man comm" for more details.
Edit: good ol' falconindy beat me to it!

Last edited by lagagnon (2010-08-27 15:09:51)


Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.

Offline

#5 2010-08-27 15:09:16

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [solved] Difference Between Two Files

cat file1 file1 file2 | sort | uniq -u

Offline

#6 2010-08-27 16:19:35

lifeafter2am
Member
From: 127.0.0.1
Registered: 2009-06-10
Posts: 1,332

Re: [solved] Difference Between Two Files

You guys rock!  Comm did what I needed it to do after I sorted the files.

Thanks!!


#binarii @ irc.binarii.net
Matrix Server: https://matrix.binarii.net
-------------
Allan -> ArchBang is not supported because it is stupid.

Offline

#7 2010-08-27 17:22:58

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: [solved] Difference Between Two Files

yes, use comm.

but just for fun:

//blue/0/~/ cat file1
a
b
c
d
//blue/0/~/ cat file2
a
s
c
t
//blue/0/~/ grep -Fxv "$(< file1)" file2
s
t

smile

Offline

#8 2010-08-28 20:57:03

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [solved] Difference Between Two Files

grep -v -f file1 file2

Offline

#9 2010-08-29 17:05:28

jvalecillos
Member
Registered: 2009-02-25
Posts: 24

Re: [solved] Difference Between Two Files

If you prefer a gui solution, i can recommend you diffuse: diffuse in aur

Last edited by jvalecillos (2010-08-29 17:06:18)

Offline

Board footer

Powered by FluxBB