hackuw
hackuw

Reputation: 1

Emeditor column swapping

I have Column A, column B, column C and column D. In column D I have valid information. I need to take the valid mail from column D, find it in column C and replace it. The mails that are not replaced should be deleted. At the same time keep the data from Column A and B for the valid mails.

Need help with Emeditor, do not advise on complex programme codes

Column A | Column B | Column C | Column D
first_name | last_name | email1_nonValid | email1 valid (this change)
first_name | last_name | email1_Valid | email1 valid (this don't change)
first_name | last_name | email1_nonValid | email1 valid (this change)

Emeditor, chat gpt, goolge, sleep

Upvotes: -1

Views: 56

Answers (1)

MakotoE
MakotoE

Reputation: 2099

You say that column D should replace column C values, but since we are finding matches, I assume this is equivalent to clearing any column C values that are not found in D.

Here is a .jsee script that will keep any column C value that exists in column D, and clear any column C value that does not exist in column D.

#language = "v8"

let lineCount = document.GetLines();
lineCount -= 1; // Subtract heading

const columnDSet = new Set();

// Add all column D values to set
// Start from line 2 and go to last line
for (let line = 2; line < lineCount + 2; line++) {
    const cellValue = document.GetCell(line, 4, eeCellIncludeNone);
    columnDSet.add(cellValue);
}

// Output column D set
//alert(JSON.stringify(Array.from(columnDSet.values())));

for (let line = 2; line < lineCount + 2; line++) {
    // Clear C if it does not exist in D
    const cellValue = document.GetCell(line, 3, eeCellIncludeNone);
    const isInColumnD = columnDSet.has(cellValue);
    if (!isInColumnD) {
        document.SetCell( line, 3, "", eeDontQuote );
    }
}

To run the macro, save the above text as a .jsee file. Go to Macros | Select... and open the .jsee file. Now open your emails file, and run the macro on it with Macros | Run [yourMacro].jsee (or Run Macro in the toolbar).

Upvotes: 0

Related Questions