943,809 Members | Top Members by Rank

Ad:
Aug 31st, 2007
0

Comparing two files and output values that match

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rusman is offline Offline
17 posts
since Feb 2006
Aug 31st, 2007
0

Re: Comparing two files and output values that match

Click to Expand / Collapse  Quote originally posted by rusman ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bob_the_welder is offline Offline
3 posts
since Aug 2007
Aug 31st, 2007
0

Re: Comparing two files and output values that match

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rusman is offline Offline
17 posts
since Feb 2006
Aug 31st, 2007
0

Re: Comparing two files and output values that match

jeez, simple as that...comm worked. I actually hadn't looked at that one. Thanks bob!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rusman is offline Offline
17 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: capturing line from script output and appending to a file
Next Thread in Shell Scripting Forum Timeline: Timestamp





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC