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”.
Press Enter.
In the command prompt, type in: cd\[the path to wher the files are located in]
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.
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++”:
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
Click on “Search”, “Bookmark”, “Toggle Bookmark”.
All the other lines are now bookmarked.
Then click on “Search”, “Bookmark”, and Remove Bookmarked lines.
Only the 0000000000001xx now remain.
This is a much easier option that writing code, excel macros or removing lines by hand.