PDA

View Full Version : Text File


brm
07-28-2004, 01:04 PM
I HAVE A TEXT FILE WITH LIST OF DRAWING CODES.

E.G.
00101000;XXXXXXXXX
00101010;XXXXXX
00101020;XXXXXXXXXX
00102000;XXX
00102010;XXXXXX
00102020;XXXXXXXXX
00301000;XXXXXXX
00301010;XXXXX

IN THE COMPLETE FILE THERE ARE 35000 CODE LINES.

I MUST SELECT THE CODES 00102000,00102010 AND 00102020.

WHAT'S THE SYNTAX TO SELECTED THIS LINES WITH 00102 FIND KEY INSERTION.

THANKS

Thom Ivancso
07-28-2004, 03:11 PM
Hello

This type of question really belongs in the Customization Fourm, so I moved it here. :)

I am not sure if you want to write the information out to a file on your system but that is how I set up this example.

I took your numeric information from the post and created a text file named "test.txt" and placed it into the C:\Temp directory.

I then ran the macro below and wrote out a file to the C:\temp directory named textlist.txt.

The macro only picks up the strings that have 00102 in them and writes these to the file.


DEFINE Find_string
LOCAL String_1
LOCAL String_2
LOCAL String_3
LOCAL String_len
OPEN_OUTFILE 2 DEL_OLD 'C:\Temp\textlist.txt'
OPEN_INFILE 1 'C:\Temp\test.txt'
LOOP
READ_FILE 1 String_1
LET String_2 (SUBSTR String_1 1 5)
IF (String_2 = "00102")
WRITE_FILE 2 String_1
END_IF
EXIT_IF (String_1 = "END-OF-FILE")
END_LOOP
CLOSE_FILE 1
END_DEFINE


Hope this helps
Cheers
Thom

Andy Poulsen
07-28-2004, 04:06 PM
Expanding a tiny bit on Thom's excellent example, adding a couple of lines will allow you to specify the text to match. (Thom probably just removed this capability to simplify the example, as the code below uses variables he had already defined!)

DEFINE Find_string
LOCAL String_1
LOCAL String_2
LOCAL String_3
LOCAL String_len
OPEN_OUTFILE 2 DEL_OLD 'C:\Temp\textlist.txt'
OPEN_INFILE 1 'C:\Temp\test.txt'
{ set up default value to match }
LET String_3 '00102'
READ 'string to match:' DEFAULT String_3 String_3
LET String_len (LEN String_3)
LOOP
READ_FILE 1 String_1
LET String_2 (SUBSTR String_1 1 String_len)
IF (String_2 = String_3)
WRITE_FILE 2 String_1
END_IF
EXIT_IF (String_1 = "END-OF-FILE")
END_LOOP
CLOSE_FILE 1
CLOSE_FILE 2
END_DEFINE

Good luck!

andy

brm
07-28-2004, 11:29 PM
Thanks for replies.
This code are in alphabetical order, is possible to end command when the find string (00102) are finished and not in END-OF-FILE.
Thanks

Thom Ivancso
07-29-2004, 03:01 AM
Hello

Can you give a sample of what the the entries look like for strings containing alpha characters


Cheers
Thom

brm
07-29-2004, 10:04 PM
With the command READ, i insert '00202', when the command find 00301000 the command must finish and the strings 00102000,00102010 and 00102020 can inserted in a logical table.

00101000;XXXXXXXXX
00101010;XXXXXX
00101020;XXXXXXXXXX
00102000;XXX
00102010;XXXXXX
00102020;XXXXXXXXX
00301000;XXXXXXX
00301010;XXXXX

Thom Ivancso
08-02-2004, 06:17 AM
Unless you know what the number sequence is going to be right after the last 00102 number is found it would be hard to have the macro end before it reaches the end of file.

Why not just let it run to the end of the file, is it a time issue?

Andy Poulsen
08-02-2004, 07:14 PM
Here's another modification that may help you. What I've done is added a couple of variables (with comments to help clarify}:

DEFINE Find_string
LOCAL String_1
LOCAL String_2
LOCAL String_3
LOCAL Found {set to 1 when matched, 0 otherwise}
LOCAL FoundCount {Total number of matches}
LOCAL String_len
OPEN_OUTFILE 2 DEL_OLD 'C:\Temp\textlist.txt'
OPEN_INFILE 1 'C:\Temp\test.txt'
LET FoundCount 0 {initialize to 0 matches}
{ set up default value to match }
LET String_3 '00102'
READ 'string to match:' DEFAULT String_3 String_3
LET String_len (LEN String_3)
LOOP
LET Found 0
READ_FILE 1 String_1
LET String_2 (SUBSTR String_1 1 String_len)
IF (String_2 = String_3)
WRITE_FILE 2 String_1
LET Found 1
LET FoundCount (1 + FoundCount)
END_IF
{ exit the loop if we're at the end of the file OR if we have }
{ previously found a match and the current line doesn't match }
EXIT_IF ((String_1 = "END-OF-FILE") OR ((Found = 0) AND (FoundCount > 0)))
END_LOOP
CLOSE_FILE 1
CLOSE_FILE 2
END_DEFINE

Note that this just code just writes the matches to a file and then exits the loop on the first non-matching line after a match has been found. You can add the logical table code to do what you need.

Please let me know if this does what you're looking for!

Good luck!

andy

brm
08-04-2004, 05:59 AM
Thank you, this suggestion is very good.