hadi motamedi
2009-Dec-02 08:54 UTC
[CentOS] Inquiry:How to compare two files but not in line-by-line basis?
Dear All Can you please do me favor and let me know how can I compare two files but not in line-by-line basis on my CentOS server ? I mean say row#1 in file1 has the same data as say row#5 in file2 , but the comm compares them in line-by-line basis that is not intended . It seems that the diff cannot do the job as well . Thank you in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20091202/e25a234d/attachment-0001.html>
Simon Banton
2009-Dec-02 09:42 UTC
[CentOS] Inquiry:How to compare two files but not in line-by-line basis?
At 08:54 +0000 2/12/09, hadi motamedi wrote:>Dear All >Can you please do me favor and let me know how can I compare two >files but not in line-by-line basis on my CentOS server ? I mean say >row#1 in file1 has the same data as say row#5 in file2 , but the >comm compares them in line-by-line basis that is not intended . It >seems that the diff cannot do the job as wellThis'll show you which lines are common to both files, and for the ones that aren't which file they're in. perl -MData::Dumper -le 'while(<>) {chomp; push @{$s->{"$_"}}, $ARGV}; END{ print Dumper($s) }' file1 file2 ... someone will be along shortly with a more elegant method. HTH S.
Brian McKerr
2009-Dec-02 09:47 UTC
[CentOS] Inquiry:How to compare two files but not in line-by-line basis?
diff -y ? On Wed, Dec 2, 2009 at 7:42 PM, Simon Banton <centos at web.org.uk> wrote:> At 08:54 +0000 2/12/09, hadi motamedi wrote: > >Dear All > >Can you please do me favor and let me know how can I compare two > >files but not in line-by-line basis on my CentOS server ? I mean say > >row#1 in file1 has the same data as say row#5 in file2 , but the > >comm compares them in line-by-line basis that is not intended . It > >seems that the diff cannot do the job as well > > This'll show you which lines are common to both files, and for the > ones that aren't which file they're in. > > perl -MData::Dumper -le 'while(<>) {chomp; push @{$s->{"$_"}}, > $ARGV}; END{ print Dumper($s) }' file1 file2 > > ... someone will be along shortly with a more elegant method. > > HTH > > S. > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20091202/0a8fcb6b/attachment-0001.html>
hadi motamedi
2009-Dec-02 10:10 UTC
[CentOS] Inquiry:How to compare two files but not in line-by-line basis?
Thank you very much for your reply . This code actually solved my problem and returned exact matches between the two files (irrespective of their location in the files) . As I understood , it will list each data showing to which file it belongs (or it is common to both files) . It is really what I wanted . Sincerely Yours On Wed, Dec 2, 2009 at 9:42 AM, Simon Banton <centos at web.org.uk> wrote:> At 08:54 +0000 2/12/09, hadi motamedi wrote: > >Dear All > >Can you please do me favor and let me know how can I compare two > >files but not in line-by-line basis on my CentOS server ? I mean say > >row#1 in file1 has the same data as say row#5 in file2 , but the > >comm compares them in line-by-line basis that is not intended . It > >seems that the diff cannot do the job as well > > This'll show you which lines are common to both files, and for the > ones that aren't which file they're in. > > perl -MData::Dumper -le 'while(<>) {chomp; push @{$s->{"$_"}}, > $ARGV}; END{ print Dumper($s) }' file1 file2 > > ... someone will be along shortly with a more elegant method. > > HTH > > S. > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20091202/42eede14/attachment-0001.html>
Paul Bijnens
2009-Dec-02 10:16 UTC
[CentOS] Inquiry:How to compare two files but not in line-by-line basis?
On 2009-12-02 11:10, hadi motamedi wrote:> Thank you very much for your reply . This code actually solved my > problem and returned exact matches between the two files (irrespective > of their location in the files) . As I understood , it will list each > data showing to which file it belongs (or it is common to both files) . > It is really what I wanted .(( do not top-post )) You could do the same by first sorting the two files, and then use "comm". -- Paul Bijnens, Xplanation Technology Services Tel +32 16 397.525 Interleuvenlaan 86, B-3001 Leuven, BELGIUM Fax +32 16 397.552 *********************************************************************** * I think I've got the hang of it now: exit, ^D, ^C, ^\, ^Z, ^Q, ^^, * * quit, ZZ, :q, :q!, M-Z, ^X^C, logoff, logout, close, bye, /bye, ~., * * stop, end, ^]c, +++ ATH, disconnect, halt, abort, hangup, KJOB, * * ^X^X, :D::D, kill -9 1, kill -1 $$, shutdown, init 0, Alt-F4, * * Alt-f-e, Ctrl-Alt-Del, Alt-SysRq-reisub, Stop-A, AltGr-NumLock, ... * * ... "Are you sure?" ... YES ... Phew ... I'm out * ***********************************************************************
Les Mikesell
2009-Dec-02 14:02 UTC
[CentOS] Inquiry:How to compare two files but not in line-by-line basis?
hadi motamedi wrote:> Dear All > Can you please do me favor and let me know how can I compare two files > but not in line-by-line basis on my CentOS server ? I mean say row#1 in > file1 has the same data as say row#5 in file2 , but the comm compares > them in line-by-line basis that is not intended . It seems that the diff > cannot do the job as well .Diff should resync after showing the some lines have been inserted. If it shows that no lines match when you think that some do, it may mean the files have different line endings. Was one created under windows or transferred in a way that could change them? -- Les Mikesell lesmikesell at gmail.com