Compare files, save differences

Visto 82 veces
Saltar al primer mensaje no leído

Jeri Raye

no leída,
21 abr 2014, 5:14:2121/4/14
a vim...@googlegroups.com
Hi,

I have a file allwords.txt.
And I have another file mywords.txt

How can I filter the differences, and safe them in another file called difwords.txt?

Example:
+------ allwords.txt -------+
James
Richard
Anna
Claude
Ben
+------------+

+------mywords.txt-----+
Anna
Ben
+-------------------+

This should then make the following file

+------difwords.txt-----+
James
Richard
Claude
+-----------+


Rgds,
Jeri

Christian Brabandt

no leída,
21 abr 2014, 5:28:2021/4/14
a vim...@googlegroups.com
Hi Jeri!
That is what external commands are good for. I would use comm(1)

#v+
/tmp/compare % comm -23 <(sort allwords.txt) <(sort mywords.txt)
Claude
James
Richard
/tmp/compare %
#v-

Best,
Christian
--
Nicht die Frau, die Kinder binden den wagenden Mut, weil wohl jene mit
uns tragen kann, da sie sich mit uns entschließt, diese aber noch
keine Kräfte zum Entschließen und Tragen haben.
-- Jean Paul

David Fishburn

no leída,
21 abr 2014, 10:16:3921/4/14
a vim_use
Jeri,

I had the same problem when I create Vim syntax files.

I have a list of "words" and I need to compare those against all the words in my Vim syntax file.  So when the product I wrote the syntax file for comes out with a new version, there is typically more "keywords" which need to be added to the syntax file.

I have a process which creates 1 file with all the keywords for the new version.  Now I need to merge that with my existing Vim syntax file.

I want to see any combination of:
1.  All words missing.
2.  All words in both (not missing).
3.  Can also do the same linewise, rather than wordwise. 

So I wrote a plugin to do it:

WhatMissing.vim - Shows what is missing between 2 buffers

It has a menu to help with the choices and getting started.

Enjoy.
David

Jeri Raye

no leída,
26 abr 2014, 10:05:3326/4/14
a vim...@googlegroups.com
Hi David,

I've installed it, and open the two files:
When I do trough the GUI or with :WhatsMissing I get the error
WM: cannot search other buffers with :set nohidden

How do I solve that?

Rgds,
Jeri


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Fishburn

no leída,
27 abr 2014, 18:54:4427/4/14
a vim_use
On Sat, Apr 26, 2014 at 10:05 AM, Jeri Raye <jeri...@gmail.com> wrote:
Hi David,

I've installed it, and open the two files:
When I do trough the GUI or with :WhatsMissing I get the error
WM: cannot search other buffers with :set nohidden

How do I solve that?


:set hidden
:WhatsMissing

David 

Charlie Kester

no leída,
29 abr 2014, 1:12:4629/4/14
a vim...@googlegroups.com
On Mon 21 Apr 2014 at 02:28:20 PDT Christian Brabandt wrote:
>That is what external commands are good for. I would use comm(1)
>
>#v+
>/tmp/compare % comm -23 <(sort allwords.txt) <(sort mywords.txt)

That's probably the best solution if you're on Unix, Linux or OS X.

Not sure if comm(1) is available by default on Windows, however.
It's been a while since I've worked on one of those systems.
I'm pretty sure you can get comm(1) by installing Cygwin, the MKS Toolkit,
or Microsoft's Subsystem for Unix-based Applications (SUA).
But if this is the only Unix-like task the OP needs done,
it might not be worth the trouble.

In general, whenever possible I prefer to use external commands
rather than plugins. If I wanted my editor to do everything itself,
I'd be using emacs. ;)


kamaraju kusumanchi

no leída,
27 jun 2014, 1:29:0227/6/14
a vim...@googlegroups.com,jeri...@gmail.com
It has been a long time since you posted this. I am not sure if you found the solution already. But since this is a problem I frequently encounter, I made a perl script to solve it. You can download it from https://sourceforge.net/p/rajuutils/code/ci/master/tree/perl/overlap/ . By default, it operates on two files setA.txt, setB.txt. The output is stored in "out" directory.

For example, with the following input files
rajulocal@hogwarts:~/work/rutils/perl/overlap$ cat setA.txt 
James
Richard
Anna
Claude
Ben
rajulocal@hogwarts:~/work/rutils/perl/overlap$ cat setB.txt 
Anna
Ben
Jeff
Raju
Run the script

rajulocal@hogwarts:~/work/rutils/perl/overlap$ ./overlap.pl 
set           count pct
A             5 0.71
B             4 0.57
A or B         7 1.00
A and B       2 0.29
A - B         3 0.43
B - A         2 0.29
notA and notB 0 0.00
storing output files under out directory

The output files are as follows:
rajulocal@hogwarts:~/work/rutils/perl/overlap$ ls out/
out_AandB.txt  out_AorB.txt  out_notAnotB.txt  out_onlyA.txt  out_onlyB.txt

In this case, the file you are interested in is out_onlyA.txt

rajulocal@hogwarts:~/work/rutils/perl/overlap$ cat out/out_onlyA.txt 
Claude
James
Richard

hth
raju
-- 
Kamaraju S. Kusumanchi

Conner McDaniel

no leída,
27 jun 2014, 9:58:3727/6/14
a vim...@googlegroups.com
You can use the `diff` program to check differences between files. You
could also use `git diff` as an alternative. If you want to view changes
interactively in vim use `:vimdiff`. Seek help for these commands in the
man pages and `:help` documentation.

- Conner

kamaraju kusumanchi

no leída,
27 jun 2014, 10:12:3727/6/14
a vim...@googlegroups.com
On Fri, Jun 27, 2014 at 9:56 AM, Conner McDaniel <conn...@gmail.com> wrote:
You can use the `diff` program to check differences between files. You could also use `git diff` as an alternative. If you want to view changes interactively in vim use `:vimdiff`. Seek help for these commands in the man pages and `:help` documentation.

- Conner
 
 
While these are all useful tools, this will not solve OP's problem. The idea here is to get the list of list of names that are in one set but not in another set and then store the results into a different file. How will you achieve this with diff, git diff, vimdiff?

Conner McDaniel

no leída,
27 jun 2014, 10:34:2827/6/14
a vim...@googlegroups.com
I apologize. You can use sort and join to get this result. For
example...

join -v1 <(sort allwords.txt) <(sort mywords.txt) >difwords.txt

- Conner

Christian Brabandt

no leída,
27 jun 2014, 10:49:3527/6/14
a vim...@googlegroups.com

On Fr, 27 Jun 2014, Conner McDaniel wrote:

> I apologize. You can use sort and join to get this result. For
> example...
>
> join -v1 <(sort allwords.txt) <(sort mywords.txt) >difwords.txt

or use comm(1) as I wrote a couple of months before.

Best,
Christian
--
Darin besteht ja die Teufelei weiblicher Reize, daß sie einen
zwingen, sein eigenes Verderben herbeizusehnen.
-- George Bernard Shaw

Conner McDaniel

no leída,
27 jun 2014, 12:05:0227/6/14
a vim...@googlegroups.com
Can you give an example? I can't get comm to produce the OP's requested
output.

Thanks!
Conner

Christian Brabandt

no leída,
27 jun 2014, 16:01:2827/6/14
a vim...@googlegroups.com
On Fr, 27 Jun 2014, Conner McDaniel wrote:

> Can you give an example? I can't get comm to produce the OP's
> requested output.

Please don't top poste. You can find the answer in the thread, you are
replying to:
https://groups.google.com/d/msg/vim_use/a_dxsQtjTbU/sPdTeTV_7FsJ

Best,
Christian
--
Windows98: 98% Grafik und 2% Betriebssystem.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos