LinuxQuestions.org
Review your favorite Linux distribution.
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
 
Search this Thread
Old 05-30-2012, 10:34 AM   #16
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by danielbmartin View Post
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
Please note that file3 is supposed to be the output file. However for sample sake please find the data below

file1 file2 file3
8120 81 No output
8124 846 No output
8140 84259 No output
8308 1234 No output
8347 833 8347
84199 555 84199
84200 8308 No output
84228 842 No output
84249 8449 No output
84250 84200 No output
84258 8766 No output
84259 23456 No output
8435 98765 8435
8437 84240 8437
8449 789 No output
84588 7654 84588
84589 345 84589
 
Old 05-30-2012, 10:36 AM   #17
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
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?
yes, correct
 
Old 05-30-2012, 10:38 AM   #18
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
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?
As for no output or empty line, which ever suits your style...
 
Old 05-30-2012, 11:02 AM   #19
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,167

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Quote:
Originally Posted by hamijami View Post
Please note that file3 is supposed to be the output file. However for sample sake please find the data below

file1 file2 file3
8120 81 No output
8124 846 No output
8140 84259 No output
8308 1234 No output
8347 833 8347
84199 555 84199
84200 8308 No output
84228 842 No output
84249 8449 No output
84250 84200 No output
84258 8766 No output
84259 23456 No output
8435 98765 8435
8437 84240 8437
8449 789 No output
84588 7654 84588
84589 345 84589
Having studied this larger sample I reach this conclusion: One of us doesn't understand the problem to be solved. With humility, I will assume that I am the dimwit and now bow out of this thread.

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

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
Maybe something like:
Code:
awk 'FNR==NR{a[$1];next}{for(i in a)if($1 ~ "^"i){print;b=1;break}if(! b)print "no output";b=0}' file2 file1 > file3
If I understood correctly.
 
1 members found this post helpful.
Old 05-31-2012, 03:07 AM   #21
hamijami
LQ Newbie
 
Registered: May 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
Maybe something like:
Code:
awk 'FNR==NR{a[$1];next}{for(i in a)if($1 ~ "^"i){print;b=1;break}if(! b)print "no output";b=0}' file2 file1 > file3
If I understood correctly.
Thanks Grail, this is the exact solution...really appreciate your effort
 
  


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


All times are GMT -5. The time now is 03:55 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration