Comparing two files and output values that match

Reply

Join Date: Feb 2006
Posts: 17
Reputation: rusman is an unknown quantity at this point 
Solved Threads: 0
rusman rusman is offline Offline
Newbie Poster

Comparing two files and output values that match

 
0
  #1
Aug 31st, 2007
Hi all,

I have two files, both have a list of 6 digit values. I want to compare them and output the values that match up. The lines in each file are not supposed to contain the same value (in other words, line 1 in each file may or may not contain the value 000001, and so on).

Thanks for the help!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3
Reputation: bob_the_welder is an unknown quantity at this point 
Solved Threads: 0
bob_the_welder bob_the_welder is offline Offline
Newbie Poster

Re: Comparing two files and output values that match

 
0
  #2
Aug 31st, 2007
Originally Posted by rusman View Post
I have two files, both have a list of 6 digit values. I want to compare them and output the values that match up. The lines in each file are not supposed to contain the same value (in other words, line 1 in each file may or may not contain the value 000001, and so on).
What is your goal here? For example, do you want to:

1. Show where the same values exist in each file and relative position
example: line3 file1 is the same as line 227 file2

2. Count the number of occurrences of same values in file1 + file2
example: 201622 occurs 1 time in both files
344702 occurs 2 times in both files
001010 occurs 2 times in both files

3. TOTAL the number of times the same value exists in each file
example: (based on #2 above) file1 + file2 have a total of 5 occurrences of the same value.

4. Query against a specific value to see if (position agnostic) it appears in both files.
example: does 001010 exist at all in file1, file2

You might wish to consider reading up on three useful utilities one or more of which may be of assistance to you.
- comm
- diff
- sort

There is a Perl script or two out there which would accomplish one or more of the example goals I wondered about above.


May the Magnificent Arc and its Gaseous Shield be with you all. Do not weld anything while standing in ankle deep water. Use eye protection at all times, and avoid flying slag like the plague. Try not to weld while drunk.
Warm Regards & HTH,
Bob The Welder
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 17
Reputation: rusman is an unknown quantity at this point 
Solved Threads: 0
rusman rusman is offline Offline
Newbie Poster

Re: Comparing two files and output values that match

 
0
  #3
Aug 31st, 2007
Originally Posted by bob_the_welder View Post
What is your goal here? For example, do you want to:

4. Query against a specific value to see if (position agnostic) it appears in both files.
example: does 001010 exist at all in file1, file2
Bob, thanks for the reply.

I am trying to achieve #4. I want to know which values from file 1 match file 2. I'll check out those commands again, but I didn't seem to see how they could be helpful.

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 17
Reputation: rusman is an unknown quantity at this point 
Solved Threads: 0
rusman rusman is offline Offline
Newbie Poster

Re: Comparing two files and output values that match

 
0
  #4
Aug 31st, 2007
jeez, simple as that...comm worked. I actually hadn't looked at that one. Thanks bob!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC