LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 05-30-2012, 05:29 AM   #1
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Rep: Reputation: Disabled
Finding the Big and Exact Match of Sample Data


Hi all,

I have data in two files and i need to find the exact and big match of values in file1 from that in file2 in new file3.

file1 file2 file3(Required Results)
7890 8900 No output
7891 7890 7891
894 7909 No output
8058 89 8058
8059 792 8059


Kindly suggest any way for the resolution of the issue.

Thanks
 
Old 05-30-2012, 05:56 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,176

Rep: Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779
Sounds good ... what have you attempted in an effort to solve the problem?
 
Old 05-30-2012, 06:27 AM   #3
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
I have use nested loop and used awk.
while read file1
do
while read file2
do
awk -F \| '{if('$file2'~"'$file1'")print"$file2"}' smc >> match
done<file2

done<file1
 
Old 05-30-2012, 06:35 AM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,032

Rep: Reputation: 275Reputation: 275Reputation: 275
Quote:
Originally Posted by hamijami View Post
I have data in two files and i need to find the exact and big match of values in file1 from that in file2 in new file3.
This sounds like an interesting problem. I know what an "exact match" is but don't recognize the term "big match." Is there such a thing as a "small match?" What is the distinction?

Daniel B. Martin
 
Old 05-30-2012, 06:47 AM   #5
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by danielbmartin View Post
This sounds like an interesting problem. I know what an "exact match" is but don't recognize the term "big match." Is there such a thing as a "small match?" What is the distinction?

Daniel B. Martin
by big match e.g.89 is a big match for 894 as it can be covered if consider 89 as 89x, x can have value from 0-9. just as like is used in SQL.

Other example of big match

9 can be considered as big match for 999.
990 can be considered as big match for 99094 etc.
 
Old 05-30-2012, 07:30 AM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,176

Rep: Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779
Well you have lost me then I thought "big match" was your way of saying one number bigger than the other.

As it is not, would you please explain further as I am not seeing how any of your examples would explain your first example, for instance:
Code:
8058	89 8058
How is 89 any sort of match in 8058??
 
Old 05-30-2012, 07:38 AM   #7
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
Well you have lost me then I thought "big match" was your way of saying one number bigger than the other.

As it is not, would you please explain further as I am not seeing how any of your examples would explain your first example, for instance:
Code:
8058	89 8058
How is 89 any sort of match in 8058??
My friend you have to see the whole file2, 89 in file2 is big match for 894(file1), hence no output, for 8058 as it has neither an exact nor big match in file2 hence its mentioned in the output file.

file1 file2 file3(Required Results)
7890 8900 No output
7891 7890 7891
894 7909 No output
8058 89 8058
8059 792 8059
 
Old 05-30-2012, 07:47 AM   #8
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,032

Rep: Reputation: 275Reputation: 275Reputation: 275
Quote:
Originally Posted by hamijami View Post
... 89 in file2 is big match for 894(file1) ...
May we say that "big match" is the same as "partial match?" Does a "big match" always start with the left-most character? If so, 89 is a "big match" for 894 but 94 is not a "big match" for 894.

Please elaborate your criteria for matches and give more examples.

Daniel B. Martin
 
Old 05-30-2012, 07:52 AM   #9
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by danielbmartin View Post
May we say that "big match" is the same as "partial match?" Does a "big match" always start with the left-most character? If so, 89 is a "big match" for 894 but 94 is not a "big match" for 894.

Please elaborate your criteria for matches and give more examples.

Daniel B. Martin
Yes Big Match is same as partial match and yes big match always starts with left most character, and yes 89 is a big match for 894 but 94 is not big match fro 894.

More Examples

1 big match for 1234534
2345 big match for 23450000
990 is big match for 9903
 
Old 05-30-2012, 08:42 AM   #10
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,032

Rep: Reputation: 275Reputation: 275Reputation: 275
Quote:
Originally Posted by hamijami View Post
Yes Big Match is same as partial match and yes big match always starts with left most character, and yes 89 is a big match for 894 but 94 is not big match for 894.
Okay, we have a better understanding of terminology. Now, going back to your original post, you gave these examples...
Code:
file1 file2 file3
7890  8900  No output
7891  7890  7891
894   7909  No output
8058  89    8058
8059  792   8059
Regarding the last line: I do not see how 8059 is a Big Match for 792.

Daniel B. Martin
 
Old 05-30-2012, 08:48 AM   #11
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by danielbmartin View Post
Okay, we have a better understanding of terminology. Now, going back to your original post, you gave these examples...
Code:
file1 file2 file3
7890  8900  No output
7891  7890  7891
894   7909  No output
8058  89    8058
8059  792   8059
Regarding the last line: I do not see how 8059 is a Big Match for 792.

Daniel B. Martin
for 8059 as it has neither an exact nor big match in file2 hence its mentioned in the output file. The output file contains all the numbers that were neither exact nor a big match.
 
Old 05-30-2012, 08:57 AM   #12
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,032

Rep: Reputation: 275Reputation: 275Reputation: 275
Quote:
Originally Posted by hamijami View Post
for 8059 as it has neither an exact nor big match in file2 hence its mentioned in the output file. The output file contains all the numbers that were neither exact nor a big match.
I had the idea that each line in file1 was compared to the corresponding line in file2. Is this wrong? Is every line in file1 compared to every line in file2?

Daniel B. Martin
 
Old 05-30-2012, 08:58 AM   #13
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by danielbmartin View Post
I had the idea that each line in file1 was compared to the corresponding line in file2. Is this wrong? Is every line in file1 compared to every line in file2?

Daniel B. Martin
every line in file1 compared to every line in file2? Yap thats why nested loop
 
Old 05-30-2012, 09:18 AM   #14
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,032

Rep: Reputation: 275Reputation: 275Reputation: 275
Quote:
Originally Posted by hamijami View Post
every line in file1 compared to every line in file2? Yap thats why nested loop
Please provide larger samples of your three files. Be sure to include cases where exact matches occur. Then we will have a better understanding of all possible cases and maybe have fun writing code.

Daniel B. Martin
 
Old 05-30-2012, 09:22 AM   #15
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,176

Rep: Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779Reputation: 1779
Still not clear to me so I will ask another question:

The format you have shown, ie file1 followed file2 and the output file3 has nothing to do with the lines being shown as they are?

What we are saying is that for any match of file2 with a line in file1 will give "No output" (is this an empty line or actually these words?) whereas, if none of the items in file2
match the line in file1 then output the file1 value.

Does that sound correct?
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
exact match in awk cristalp Programming 20 09-19-2011 01:31 PM
Using grep to find EXACT MATCH andy2008 Programming 13 11-16-2010 06:48 AM
[SOLVED] Match datetime by the minute (not an exact match by the second) [mysql] hattori.hanzo Programming 1 10-21-2010 05:43 PM
egrep for only words(exact match) msgforsunil Linux - Newbie 4 04-14-2010 05:27 AM
how to find an exact substring match? ldp Programming 7 02-22-2005 06:28 AM


All times are GMT -5. The time now is 08:38 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration