You are not logged in.

#1 2009-01-01 17:10:20

Xauthority
Member
From: ../
Registered: 2008-11-03
Posts: 61

Help with diff

Hi all,
I try with diff to compare 2 text files, but I want only to
get the exact output.
I mean like
file 1:

Hello
World
How
Are
You

file 2:
Hello
How
Are
You

diff file1 file2 to have the output "World"

Thanks for any help
__________________

Offline

#2 2009-01-01 20:03:41

Hrod beraht
Member
Registered: 2008-09-30
Posts: 186

Re: Help with diff

diff file1 file2 | awk 'NF > 1 {print $2}'

The awk part means look for lines with number of fields (NF) greater than 1 ('< world' in a normal diff output), and print the second field, i.e. world, but not the < or >.
It will print each difference on a new line if there is more than one.

Bob

Last edited by Hrod beraht (2009-01-01 20:13:02)

Offline

#3 2009-01-01 20:28:26

Xauthority
Member
From: ../
Registered: 2008-11-03
Posts: 61

Re: Help with diff

Well this also dont output only the differences.
What I am trying to do is create .reg file from differeny WINEPREFIXES and compare their
user.reg / system.reg and create from the differences .reg files, which can be used
to simply fix some entries via regedit mykey.reg.
So what I need is a way to compare them keep and also keep the new lines.

diff file1 file2 | awk 'NF > 1 {print $2}'

This was quite unusable because it removes more than just the < and line numbers
it removes some of the entries and parts of the syntax of the registry like  } at the end
of the line.

Offline

#4 2009-01-01 20:56:05

Hrod beraht
Member
Registered: 2008-09-30
Posts: 186

Re: Help with diff

Xauthority wrote:

...it removes...parts of the syntax of the registry like  } at the end of the line.

Quite right. I think I took your original example too literally smile If you are using complex lines with more than just a single word, it would have to look like this in order to report all fields after the < or >:

diff file1 file2 | awk 'NF > 1 {print substr($0,index($0,$2))}'

So with two files of:

File 1:
hello
world
how
are
you

File 2:
hello
how
are
you two three four } +

the above would return:

world
you two three four } +

But are you looking for just added lines that are in one file but not the other?  How about changed lines?
for example:

File 1:
hello
world

File 2:
worlld

Do you want differences reported as well as completely new/additional lines? That is, should the two files above report the following?

hello
world
worlld

Bob

Offline

#5 2009-01-02 11:32:19

Xauthority
Member
From: ../
Registered: 2008-11-03
Posts: 61

Re: Help with diff

Hi bob,
thank you for answering but I managed it now with a program
called "wdiff". It almost made it. (I had to edit some lines of the source code)
So it does now ( wdiff -1 -3 file1 file2 > file3 )

file 1:
{DATE}
=01.01.2009

{HAPPY NEW YEAR}

{How_ARE_YOU}
=FINE

file 2:
{DATE}
=02.01.2009

{How_ARE_YOU}
=FINE

{HELLO WORLD}

file 3
=02.01.2009

{HELLO WORLD}

Thats what I needed

Last edited by Xauthority (2009-01-02 11:34:35)

Offline

Board footer

Powered by FluxBB