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!

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

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!

jeez, simple as that...comm worked. I actually hadn't looked at that one. Thanks bob!

This article has been dead for over six months. Start a new discussion instead.