Search code examples
csvemeditor

How can you delete the first and fifth columns from 100 CSV files with EmEditor?


I have about 100 CSV (comma-separated) files. A sample CSV file is:

1,222,33,444,5
6,777,88,999,0

What is the best way to remove the first and fifth columns from all these CSV files with EmEditor?


Solution

  • First, create a macro to delete the first and fifth columns from a CSV document. After you open a CSV file with EmEditor (v21.0.0 or later), ensure the macro file works with one CSV document. To run a macro, save the code below as, for instance, RemoveColumn.jsee, and then select this file from Select... in the Macros menu. Finally, select Run RemoveColumn.jsee in the Macros menu.

    RemoveColumn.jsee

    editor.ExecuteCommandByID(22528); // select CSV mode
    document.DeleteColumn( 5 );  // Delete Column 5
    document.DeleteColumn( 1 );  // Delete Column 1
    

    After you confirm the macro works, we will apply the macro to 100 CSV files.

    To do this, select Run with Temporary Options on the Macros menu, ensure RemoveColumn.jsee is already specified in the Macro text box, set the Run the macro against each opened document and Save and close each document after running the macro options, drag and drop (or click the Add button and select) all CSV files you want to apply the macro, and click Run.

    EmEditor - Macro Temporary Options

    This should remove the first and fifth columns from all the specified CSV files.