FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 12-02-2009, 08:42 AM
Simon Banton
 
Default 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 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:umper -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@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-02-2009, 01:02 PM
Les Mikesell
 
Default 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@gmail.com
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-03-2009, 01:42 PM
 
Default Inquiry:How to compare two files but not in line-by-line basis?

> From: mark <m.roth@5-cent.us>
>> John Doe wrote:
>> > From: hadi motamedi
>> >> Can you please do me favor and let me know if I can go further and
>> try for advanced search like finding how many rows inside a file have data
>> that does not start with a zero after the third comma ?
>> >
>> > Something like: awk -F, ' { print $4 } ' | grep -v "^0" | wc -l Use
>> one command at a time to see how they work with each other (you might have
>> to modify the grep a bit)...
>>
>> *sigh*
>>
>> Drive me crazy, why use multiple commands?
>>
>> awk -F 'BEGIN { FS = ","; }{if ( $3 !~ /^0 ) { count++; }} END { print
>> count }'
>> filename
>
> Oh no!!! Don't get mad!!! ^_^
> Teaching some UNIX pipes to a "beginner" can be helpful you know...
> And it is $4...

You're right, it is $4, but what do you want, I was still half asleep, and
getting ready to head to work....

And yeah, pipes are Good. I try to explain to folks why I call *Nix "fun",
and one reason is the huge toolset that's *intended* to work together.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 10:15 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org