What We Are Trying to Accomplish
- Combine a collection of daily files into a single text file
- Then filter this combined file 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”.
In the command prompt, type in: cd\[the path to wher the files are located in]
Type the following command:
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:
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 “|”:
Click on “Search”, “Bookmark”, “Toggle Bookmark”.
All the other lines are now bookmarked.
Then click on “Search”, “Bookmark”, “Toggle Bookmark”.
Remove Bookmarked lines.
Only the 0000000000001xx now remain.
This is a much easier option that writing code, excel macros or removing lines by hand.