Last active
January 15, 2017 22:45
-
-
Save onokhov/f65c179b98dcf480d0472d489241b8f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(cf). | |
-export([compare_files/2]). | |
compare_files(FileName1, FileName2) -> | |
OS1 = ordset_from_file(FileName1), | |
OS2 = ordset_from_file(FileName2), | |
OS1_uniq = ordsets:subtract(OS1, OS2), | |
OS2_uniq = ordsets:subtract(OS2, OS1), | |
case {OS1_uniq, OS2_uniq} of | |
{[],[]} -> io:format("files ~s and ~s are identical~n", [FileName1, FileName2]); | |
{_, []} -> print_uniq(FileName1, OS1_uniq); | |
{[], _} -> print_uniq(FileName2, OS2_uniq); | |
{_, _} -> | |
print_uniq(FileName1, OS1_uniq), | |
print_uniq(FileName2, OS2_uniq) | |
end, | |
ok. | |
ordset_from_file(FileName) -> | |
{ok, F} = file:open(FileName,[read]), | |
OS = ordsets:from_list(read(F)), | |
file:close(F), | |
OS. | |
read(F) -> | |
read(F, []). | |
read(F, Acc) -> | |
case file:read_line(F) of | |
eof -> | |
Acc; | |
{ok, Data} -> | |
{I,_} = string:to_integer(lists:nth(3, string:tokens(Data, ";"))), % выбираем третью колонку | |
read(F, [ I | Acc ]) | |
end. | |
print_uniq(FileName, List) -> | |
io:format("file ~s contains uniq: ", [FileName]), | |
[ io:format("~w ", [X]) || X <- List ], | |
io:format("~n"). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment