[SOLVED] Finding the Big and Exact Match of Sample Data
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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?
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.
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.
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.
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
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.
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.
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?
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.