Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

use diff to get same and different rows

2 views
Skip to first unread message

ela

unread,
Nov 18, 2008, 6:03:28 PM11/18/08
to
after man diff, it seems that I cannot generate the 2 output files simply
from files a & b?

file a:
1 2 3
1 1 1

file b:
1 1 1
1 3 9
2 2


OutputSame:
1 1 1

OutputDiff:
file a 1 2 3
file b 1 3 9
file b 2 2


Peter Havens

unread,
Nov 18, 2008, 7:43:59 PM11/18/08
to
On Nov 18, 4:03 pm, "ela" <e...@yantai.org> wrote:
> after man diff, it seems that I cannot generate the 2 output files simply
> from files a & b?

I'm not sure I understand what you mean, but if you want to do a
comparison without regard to where lines appear in each file (which
seems to be what you want), you could probably use the `comm` command.
For example, to get lines that are common to both files, you might try
something like:

bash$ comm -12 <(sort a) <(sort b)
1 1 1

...or to get lines that are not common to both files:

bash$ comm -13 <(sort a) <(sort b); comm -23 <(sort a) <(sortb)


1 3 9
2 2

1 2 3

I hope that helps.

-- Pete

ela

unread,
Nov 19, 2008, 1:35:04 AM11/19/08
to

"Peter Havens" <peter....@gmail.com> wrote in message
news:78c5cf0f-4e64-412d...@i18g2000prf.googlegroups.com...

bash$ comm -12 <(sort a) <(sort b)
1 1 1

...or to get lines that are not common to both files:

bash$ comm -13 <(sort a) <(sort b); comm -23 <(sort a) <(sortb)
1 3 9
2 2
1 2 3

I hope that helps.

-- Pete

When files a & b both contain the following line,

11821 0 -2 ?->-

comm can't recognize it to be the same. Is there something dealing with the
<( ) and sort mentioned by you? Because I omitted them, which otherwise
caused execution error.


bugbear

unread,
Nov 19, 2008, 4:54:36 AM11/19/08
to
ela wrote:
> When files a & b both contain the following line,
>
> 11821 0 -2 ?->-
>
> comm can't recognize it to be the same. Is there something dealing with the
> <( ) and sort mentioned by you? Because I omitted them, which otherwise
> caused execution error.

Is the whitespace identical ? Trying checking with a hex editor, or cat -evT
or similar.

ela

unread,
Nov 19, 2008, 8:16:44 AM11/19/08
to

"bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
news:-dOdnThxu9Mcfr7U...@posted.plusnet...

The text is generated by program and therefore should not have typo or any
manmade errors. Another point I'm thinking about is whether ? or > alike are
reserved words that drive comm crazy


bugbear

unread,
Nov 20, 2008, 4:26:32 AM11/20/08
to
ela wrote:
> "bugbear" <bugbear@trim_papermule.co.uk_trim> wrote in message
> news:-dOdnThxu9Mcfr7U...@posted.plusnet...
>> ela wrote:
>>> When files a & b both contain the following line,
>>>
>>> 11821 0 -2 ?->-
>>>
>>> comm can't recognize it to be the same. Is there something dealing with
>>> the <( ) and sort mentioned by you? Because I omitted them, which
>>> otherwise caused execution error.
>> Is the whitespace identical ? Trying checking with a hex editor, or
>> cat -evT
>> or similar.
>
> The text is generated by program and therefore should not have typo or any
> manmade errors.


Did you check?

BugBear

gerard

unread,
Nov 20, 2008, 5:52:15 AM11/20/08
to

if yur problem is related to patches, i suggest you take a look at
vsrpatch (Versus patches):
http://www.solaris-fr.org/home/contribs/sys/vrspatch_en

Harry

unread,
Nov 20, 2008, 12:54:43 PM11/20/08
to

diff is perfectly fine for you.

$ diff --unified=1000 "file a" "file b" | egrep -v "\-\-|\+\+|@@"
| sed -e 's/-/file a /;s/+/file b /;s/^ /file a+b /'


file a 1 2 3

file a+b 1 1 1

0 new messages