LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 04-03-2014, 10:23 AM   #1
vinang
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Rep: Reputation: Disabled
Question Find the common / matching words


Hi All,
I would like to find the common words in file1.par with l_file2.par, l_file3.par & l_file4.par .
This is a Solaris platform .

Thanks for your help.
 
Old 04-03-2014, 10:32 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
maybe you can loop thru each word in the first file to grep thru the other files.
 
Old 04-03-2014, 10:38 AM   #3
vinang
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks schneidz.
Do you have a script handy ?

Thanks.
 
Old 04-03-2014, 11:47 AM   #4
vinang
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hello anyone there to help me , please .
urgent .
 
Old 04-03-2014, 11:48 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
what have you tried and where are you stuck ?

what is the layout of the input file and what do you want the output to look like ?
 
Old 04-03-2014, 03:41 PM   #6
vinang
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
File 1 - content
----------
tables='abc.emp' ,'bcf.customer', 'abc.client'

file 2 - content
----------
tables='bcf.customer', 'bcf.admin', 'zyx.contractor'


file 3 - content
----------
tables='bcf.customer', 'abc.client '
 
Old 04-03-2014, 03:50 PM   #7
vinang
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
this is what i have tried but didn't help ,

awk -v file=file1.txt 'BEGIN { while ( getline < file ) arr[$0]++ }( $1 in arr )' mainfile.par
 
Old 04-03-2014, 04:03 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
i would never of been able to guess that formatting without an example (i am still confused as to what you actually want in the output.

i would use things like sed or tr to filter a list of words that you want and then compare them against whatever files you want compared.

shot in the dark of what the op is trying to do:
Code:
[schneidz@hyper ebay]$ head file*
==> file1 <==
tables='abc.emp' ,'bcf.customer', 'abc.client'

==> file2 <==
tables='bcf.customer', 'bcf.admin', 'zyx.contractor'

==> file3 <==
tables='bcf.customer', 'abc.client '
[schneidz@hyper ebay]$ for word in `sed s/tables/""/ file1 | tr "=\'," "  \n"`
do 
 grep -o $word file2 file3
done
file2:bcf.customer
file3:bcf.customer
file3:abc.client

Last edited by schneidz; 04-03-2014 at 04:50 PM.
 
Old 04-03-2014, 04:40 PM   #9
vinang
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
I'm trying to find out are there any words present in flie2, files 3 are in file 1 .
 
  


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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 06:30 PM
wc to list most common words stevo520 Linux - Newbie 2 06-26-2012 07:30 PM
Can I use grep to find two words near each other? walterbyrd Linux - Software 4 12-10-2011 12:01 AM
how to capture the line after the matching words another 1 Linux - General 2 11-15-2011 08:22 AM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 06:55 PM


All times are GMT -5. The time now is 04:11 AM.

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