LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 03-23-2005, 01:57 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
find the same content in the file


I have two files ( eg. file1 and file2 ) , its contents are as below , I want to find out the same content ( same word ) in the two files , in the below example , the same content is "aaa" , could suggest how to do it ? thx in advance.


#vi file1
aaa
bbb
ccc
ddd


#vi file2
111
222
333
aaa
 
Old 03-23-2005, 02:16 AM   #2
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
the command is find - check the switches with find --help or man find
 
Old 03-23-2005, 02:26 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Hi ust,
You can't use find to get same content. Instead you must use a gawk script to do the job. Make your own gawk script. Help at "info gawk"

My site Veera's
 
Old 03-23-2005, 02:53 AM   #4
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
My apologies on find but you will find a neat little app at;

http://plagiarism.phys.virginia.edu/software.html
 
Old 03-23-2005, 02:58 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Won't this do:

Code:
for THIS in `cat file1 | grep -v '#'`
do
grep $THIS file2
done
Or as 'oneliner':

for THIS in `cat file1 | grep -v '#'`; do grep $THIS file2 ; done

Will need some work if the inputlines have 'funny' characters.

Hope this helps.
 
Old 03-23-2005, 03:03 AM   #6
prasanta
Member
 
Registered: Mar 2005
Location: India
Distribution: Debian
Posts: 368

Rep: Reputation: 37
#comm -1 -2 file1 file2
provided the files are sorted.

-Prasanta

Last edited by prasanta; 03-23-2005 at 03:04 AM.
 
  


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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
How to find files with the necessary content? kornerr Linux - General 6 08-09-2005 05:48 AM
awk and change file content Ayman.mashal Programming 4 06-02-2005 06:03 AM
How to re-build a corrupted content file ? ]un]ie Solaris / OpenSolaris 0 09-06-2004 05:16 AM
Where can I find source code for CPRM (content protection for recordable media)? George2 Linux - Security 2 02-26-2004 12:02 AM

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

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