© Matti Mattila, CPFA, CISA, CIA

9. Macro removing/keeping certain lines of a (raw) text file (LIM2)

Previous Item Previous menu
LIM2 macro, introduced here, is an improved version of LIMM macro, introduced on the previous page. The macro performs the task that LIMM does. If you have a(n) (ASCII fixed lenght) text file with extra records you can remove them before importing the data to IDEA. But LIM2 is also able remove all other lines except those containing a character string in certain line positions of a (raw) text file. E.g. if you have a big mass of records you can extract to a new file the records that you need, e.g. those of certain voucher type.
The string and the line positions (criteria) are chosen by the user. The lines of the orginal file are written into a new file except those fulfilling the (removal) criteria. The original file remains unchanged. The new file bears the body of the name of the original file extended with "_2." (e.g. sales.txt -> sales_2.txt).
Due to the functionality of IDEAScript each line of the new file starts and ends with a quotation mark ("). As a result each file of the new file is two characters longer than the original line, and the file size is bigger respectively.
The macro has been made with IDEA 2002. It is possible that IDEAScript of newer IDEA versions are not able to execute the macro properly.
Running the macro [1].
- Start IDEA after unzipping the contents of LM2.ZIP to a folder that you prefer. LM2.ISS is a demo version of LIM2.ISS.
Picure 1
Picure 2
Picture 4
- Select: Tools - Macros - Run. In the dialog box select file type '*.ise' (a compiled macro) and thereafter select LM2.ise as shown in the picture to the right (Picture 1).
- You are first shown the macro information (Picture 2). Click 'Select a File' to go on, and you are shown contents of 'lm2.txt' (not shown here). Click 'OK' after reading it.
- In the example here we have a data file 'G99A.TXT' consisting of 5.834 lines, each 242 characters long (not shown here). We select this file and get the message in picture 3.
Picture 3
- We want to remove lines where there is text 'CFD01' in positions 59-63. We submit this information and click 'OK' (Picture 4).
- The macro performs its job quickly, and gives us the message in picture 5.
- The macro performs its job quickly, and gives us the message in picture 5.
Picture 5
- NOTE! Because the macro is a demo version, only 500 first lines of the original file were processed; in this case 349 lines were not copied into the new file.
- Finally we check the new file 'G99A_2.TXT': [2] We open it with Notepad. We can see that the lines start and end with quotation marks. We can remove the quotation marks with RemQ.EXE [3].
Download
You can download the macro here. The zip file 'lm2.zip' contains files 'LM2.ise', 'lm2.txt' and 'readme_lm2.txt' and RemQ.EXE. NOTE! If you make any change in 'lm2.txt' the macro cannot be run.

[1] See also the instructions in the 'readme_lm2.txt' file. Before running the macro you should also examine the orginal file to determine the criteria: the string and its first position. IDEA's RDE has tools for this exercise.
[2] Link to the new file (G99A_2.TXT)
See also functionality of 'ImpAny' Excel macro in filtering desired text file lines into a new file.