HowTo

Combine Files and Filter to Multiple Files by Field in Minutes

Combine Text Files and Filter to Multiple Files by Field
Written by Izak Van Heerden

What We Are Trying to Accomplish

  • Combine a collection of daily files into a single text file
  • Then filter this combined file to new files by some of the fields inside.

Our Example Files

Combine a Collection of Files Into a Single Text File

In Windows 10, click on the search bar, and type “cmd”.

Combine Text Files and Filter to Multiple Files by Field

Press Enter.

In the command prompt, type in: cd\[the path to wher the files are located in]

Combine Text Files and Filter to Multiple Files by Field

   

Press Enter.

Type the following command:

    for %f in (*.txt) do type “%f” >> c:\play\combined.txt

Where the files to combine has a .txt extension and the destination file is called combined.txt.

Filter Combined File By a Field

Now that all the lines are in a combined file, we want to filter the file into two files, based on the values in the last column.

Combine Text Files and Filter to Multiple Files by Field

For exercise sake, let’s say we want to filter the above, based on the value of the last column, which is store numbers in our example.

The unique store numbers are:

  • 000000000000123
  • 000000000000125
  • 000000000000128
  • 000000000000129
  • 000000000000243
  • 000000000000296
  • 000000000000299

If we want to group store numbers 123 to 129 in one file, and the 243 to 299 in another, an option apart from splitting the file by hand, is to write a program, read in the lines, and insert some IF statements. Both options are time consuming.

An easier way is to use the Mark function on a text editor like Notepad++, which will not take more than a minute or two.

Notepadd++ can be installed from here.

After installation has completed, in Explorer, right click on the combined file and select “Edit with Notepad++”:

Combine Text Files and Filter to Multiple Files by Field 05

From the menu bar, select Search, Mark.

Under Search Mode, select the Regular Expression radio button. Also click on “Bookmark line”.

Under Find what: Enter the first batch of store numbers, separated by “|”:

000000000000123|000000000000125|000000000000128|000000000000129

Combine Text Files and Filter to Multiple Files by Field

Click on “Search”, “Bookmark”, “Toggle Bookmark”.

All the other lines are now bookmarked.

Then click on “Search”, “Bookmark”, and Remove Bookmarked lines.

Combine Text Files and Filter to Multiple Files by Field

Only the 0000000000001xx now remain.

This is a much easier option that writing code, excel macros or removing lines by hand.

About the author

Izak Van Heerden

Izak has witnessed a couple of decades worth of changing tech. He hopes to make it a couple more until his conscience can be copied to a cyborg body.

Leave a Comment

Comments Protected by WP-SpamShield Spam Plugin