Parse a .txt file

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ADP_MAN
Junior Coder
Posts: 45
Joined: Wed Apr 07, 2004 2:04 pm

Parse a .txt file

Post by ADP_MAN » Thu Jun 10, 2004 9:44 pm

Hi all,

Just to start off, I did go through the archives and looked up parsing. There were some helpfull answers, but I'll admit - I'm still a llittle lost on some of the solutions.

I have a file that looks like this:

00REP4835011210111739HENRYV 011210
01PMT00001HENRYV 323118135 0000001112491400112100000000000001009
01PMT00002HENRYV 323118135 0000019000000000112100000000000001045
990003000000000000011612600000000049340325150

I need to delete the first and last rows. I also need to remove spaces and deliniate the information using commas for the remaining rows.

Any suggestions on how to do this? Thanks in advance.

ADP_MAN

Lumumba

Post by Lumumba » Thu Jun 10, 2004 11:05 pm

I need to delete the first and last rows.
Ignore all lines which didn't contain the string PMT = Position>
I also need to remove spaces and deliniate the information using commas for the remaining rows.
Than separate the values (and get rid of the space chararcters/delimeters) = Separate>

ADP_MAN
Junior Coder
Posts: 45
Joined: Wed Apr 07, 2004 2:04 pm

Post by ADP_MAN » Fri Jun 11, 2004 1:07 pm

For the Seperate command, its says "Separate>list,delimiter,returnvar"

What would the "list" be if I was working off of one file? In other words, if my file name was "Jones.txt" would I type:

Seperate>Jones.txt,,,information

Would this then parse the "Jones.txt" file using commas? Also, how would it know where to parse? Should I put a space " " in the "delimiter" filed instead of a comma? Thanks again.

Lumumba

Post by Lumumba » Fri Jun 11, 2004 4:00 pm

OK let's have a look ...

With Autohotkey (another advanced scripting tool) you would use these commands

IfInString - Checks if a variable contains the specified string.
then
StringReplace - Replaces the specified substring with a new string
or
StringSplit - Divides a string into an array of substrings using the specified delimiters
or
Loop, parse - Retrieves substrings (fields) from a string, one by one.

Macro Scheduler offers you the option to use Visual Basic Script (VBS) to use an equivalent funtionality within your scripts. Using its standard commands to parse files can be a challenge and is less flexible. Lets assume ...

a) your file has only 4 lines by default (and only the 2nd and 3rd line are of interest to you)
b) those lines are following a field (length) specification
01PMT00002HENRYV 323118135 0000019000000000112100000000000001045
Let>ln=1

Label>ParseFile
Add>ln,1
ReadLn>C:\MyInputFile.txt,%ln%,Line
MidString>Line,1,16,1stColumn
MidString>Line,18,9,2ndColumn
MidString>Line,28,37,3rdColumn
MessageModal>%1stColumn%,%2ndColumn%,%3rdColumn%
WriteLn>C:\MyOutputFile.txt,Result,%1stColumn%,%2ndColumn%,%3rdColumn%
If>ln3, ParseFile

Label>Exit
Wait>2
Execute>C:\MyOutputFile.txt

ADP_MAN
Junior Coder
Posts: 45
Joined: Wed Apr 07, 2004 2:04 pm

Post by ADP_MAN » Fri Jun 11, 2004 4:06 pm

Lumumba,

Thank you so much for your help!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts