BeyondCompare: Replace first 6 digits if different via macro

133 views Asked by At

we are using BeyondCompare 4 to compare two files. Is there a way to use BeyondCompare in such way that by pressing a button only the first 6 digits are copied from file A to file B?

I do not want to copy the entire line and we need to check and review if we really want to replace the first digits. So we can't use any automatic replacement via macros.

E.g.:

FileA:
(ABCD)  This is a testline
(----)  This is the 2nd line


FileB:
(0000)  This is not a testline
(ABCD)  This is the second line

After reviewing it, the new file should be FileB with the first digits of the first line of FileA:

Result:
(ABCD)  This is not a testline
(ABCD)  This is the second line

Thanks in advance,

3

There are 3 answers

1
knut On BEST ANSWER

I found a tricky solution.

First you need a a new file format, defined as a table format.

  1. Tools -> File Formats
  2. Press the + and select table format
  3. Define a mask (in my case *.yyy)
  4. Set the type delimited and define a character that separates your first characters: enter image description here

After this, you can compare your two files (in my case with extension yyy): To get the correct alignment, you must make the first column to a standard column (No key column): enter image description here Now you can go to the "Text detail" area (if you don't have it, make it visible with View->Text Detail). Here you can go to one column and copy it to the right: enter image description here

Now you copied only one part of your file.

Remark:

I tried also the type fixed. The with of the first column must be as large as you need for the first digits. Then make a large 2nd column to get all other data: enter image description here This results in the following comparison: enter image description here But with this comparison I was not able to copy a single column (@Scooter-Team: Maybe this is a bug?)

0
Cleese On

Thanks a lot for the detailed description. I tried it out what Knut suggested and it worked but I needed to make a minor adjustment as in my used files there were larger lines and BeyondCompare could not identify those lines always correctly. What did work good for me, was to set ")" as delimiter. Then I could find the first 6 digits and the rest would be handled as text for comparision.

The comparison with fixed type did also not work for me. Each different lines were found but it replaces the line with only the first 6 digits when I select the cell in the line details. This approach would be ideal, if only I could replace just the first digits and not replace the entire line with the first digits.

0
Chris Kennedy On

The only way to copy a portion of a line in Beyond Compare's Text Compare is to use Copy and Paste. The Copy command will always copy the entire line.

Knut's method using the Table Compare is the only workaround.