7

For example, I have a text file, each line is a long string. I want to exclude 2 "segments" of this string, say columns 1-7 and 20-22. So the bottom 2 lines below would be a match:

123456789012345678901234567890 
------------------------------
xxxxxxxAAAAAAAAAAAAxxxBBBBBBBB
yyyyyyyAAAAAAAAAAAAyyyBBBBBBBB

I know WinMerge has a "IgnoreColumns" plugin but I have never go this working. In this example I would rename it IgnoreColumns_1-7, 20-22.dll, select it in the plugins menu, and choose "Pre-Differ." but it has never worked.

I am going to be comparing huge files that I don't want to modify. I'm not opposed to stream editing them in the comparison with sed or something like that, but I would prefer not to modify the actual files. I have not chose to feed sed to diff yet just because I was hoping for for a more visual view of the data.

1
  • Do you have the program open or closed when you're renaming the file? Maybe you need to restart WM or reload plugins. I just tried WinMerge (ver 2.13.20): put each line of your sample into a different file, and diffed them. WinMerge showed the difference at first, but once I loaded the plugin it said that they were identical.
    – afrazier
    Jul 29, 2011 at 19:45

4 Answers 4

6

The following works on Linux and on Cygwin.

vimdiff <(cut -c8-19,23- file1) <(cut -c8-19,23- file2)

For some reason on Cygwin, Vim prompts that each file has changed since editing started and asks, "[O]K, (L)oad File:". Just type O each time.

Granted you don't get to see the omitted columns, but it is a visual, side-by-side comparison.

3

If you'd still like to get the WinMerge "IgnoreColumns" plugin working... it looks like you're close. Two notes:

  1. For your example, in WinMerge's MergePlugins subfolder, copy IgnoreColumns.dll to IgnoreColumns_1-7_20-22.dll (no spaces, and using underline instead of comma).

  2. Exit WinMerge entirely, and re-run it, after placing that DLL. ("Reload plugins" will update the Plug-ins / List pull-down menu, but will not update the functionality.)

Side note: I recommend a "supported but unofficial" version of WinMerge – 2.13.20.12 – that includes 3-way comparisons. Go to Unofficial WinMerge builds, and at the bottom you'll see the "3-way diff supported version".

1

Just as Diogo_Rocha's answer, you could modify the file beforehand to remove the columns you do not want to test, then run diff. But with just commandline stuff.

So for your example, removing 'columns' 1-7 and 20-22 you could.

sed 's/.\{7\}\(.\{12\}\).\{3\}\(.*\)/\1\2/' test.txt > test2.txt
diff -u test2.txt whatnot.txt

Edit: Blatant thieverizing of garyjohn's better answer.

diff -u <(cut -c8-19,23- test1.txt) <(cut -c8-19,23- test2.txt) | less
2
  • question updated. i have a lot of files so copying would be a pain, but might be the best bet. but I guess my original question stands - is there a diff utility that does this out of the box?
    – user39160
    Jul 29, 2011 at 19:18
  • Essentially garyjohn's answer is what you need. No need to duplicate files, feed modified files on stdin to diff or his version with vimdiff. And easier with cut rather than sed.
    – Nicholi
    Jul 29, 2011 at 20:01
0

If I could understand your doubt, you are trying to exclude or select specific colums from a text file. If it is true, you can do it with the textpad application. Install it and open your text file, then press your "Alt" key on the same time that you select specific colums from your text. With these colums selected you can copy, cut or delete each one you need.

1
  • question updated
    – user39160
    Jul 29, 2011 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .