LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-23-2011, 01:46 AM   #1
Dr_Death_UAE
Member
 
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Rep: Reputation: 30
how to show only unique words between two files


Hi, i have to files
Quote:
File1:
Hi, My name is John smith
Quote:
File2:
Hi, My name is smith
I want to show only the different or unique word between the two files (John)

i was trying to get it with diff, comm, sort, uniq, grep, awk, sed

but no luck, if anyone have an idea how to do it please advice

Thanks
 
Old 02-23-2011, 02:03 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

Have a look at wiggle. This tool can do word based comparison. The different word will be put between <<<-- word-->>>.

Kind regards,

Eric
 
1 members found this post helpful.
Old 02-23-2011, 02:26 AM   #3
Dr_Death_UAE
Member
 
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Original Poster
Rep: Reputation: 30
thanks EricTRA, but is there a way to do it with shell commands
 
Old 02-23-2011, 02:32 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

I'm sure there will be but it will involve some scripting, like in the following thread I found, which has a Python and Awk example. Is there a special reason why you don't want to install a tool but prefer writing a script? Besides the obvious reason of learning?

Kind regards,

Eric
 
Old 02-23-2011, 03:10 AM   #5
akelder
Member
 
Registered: Jan 2007
Distribution: debian on servers, ubuntu on desktops/laptops
Posts: 45

Rep: Reputation: 16
This is probably goofy, but you could put every word on it's own line:

Code:
$ cat file1
Hi, My name is John smith

$ cat file2
Hi, My name is smith

$ sed 's/ /\n/g' file1 > file1.tmp
$ sed 's/ /\n/g' file2 > file2.tmp

$ comm -3 file1.tmp file2.tmp
John

$ sort file1.tmp file2.tmp | uniq -u
John
 
Old 02-23-2011, 05:18 AM   #6
Dr_Death_UAE
Member
 
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Original Poster
Rep: Reputation: 30
i want to include this code in a shell script that will be use in a different machines, it's better to make it run with the basic linux shell commands.

thanks akelder, this what i was looking for, i pipe the commands and it work fine:

Quote:
$ cat file1 file2 | sed 's/ /\n/g' | sort | uniq -u
john

Last edited by Dr_Death_UAE; 02-23-2011 at 05:20 AM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How would I ignore other lines in a file with non unique words? btacuso Linux - Newbie 1 05-24-2009 08:20 AM
Show unique values with related data in one line cgcamal Programming 1 11-21-2008 02:48 AM
How to count occurrences of unique words in a file beeblequix Linux - General 3 01-14-2007 03:47 PM
How do I show the structur of directory with words? pelgrim Linux - Newbie 4 03-17-2003 06:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:49 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