Edit ini file

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Davd K
Newbie
Posts: 7
Joined: Wed Jun 16, 2004 4:00 am

Edit ini file

Post by Davd K » Tue Jul 13, 2004 6:40 pm

I want to check an file at a particulat column and if the certain characters appear, delete the entire line.

Then I need to edit each line at particular columns to replace the text with my new text.

How do I do this?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Jul 13, 2004 8:53 pm

Here's a rough skeleton of commands to do what you want.

Read each line of the INI:
ReadIniFile>inifile,section,entry,result

Use MidStr to look at certain column positions:
MidStr>%result%,start,length,result2

Use IF to make decisions:
If>%result2%=value,true_label_name[,false_label_name]

Use EditIni to replace lines:
EditIniFile>inifile,section,entry,newvalue
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Davd K
Newbie
Posts: 7
Joined: Wed Jun 16, 2004 4:00 am

Post by Davd K » Wed Jul 14, 2004 3:04 pm

This isn't a "typical" ini file that has sections in it. It is just a basic txt file that I need to do this to.

How would I read each line in a basic txt file?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Jul 14, 2004 6:56 pm

Replace ReadINI with ReadLn

Replace EditINI with WriteLn

See Help for changes to syntax and examples.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Davd K
Newbie
Posts: 7
Joined: Wed Jun 16, 2004 4:00 am

Post by Davd K » Thu Jul 15, 2004 3:07 pm

I do understand how to read in the line but once I have the line I need to go over to column 70 and 71 and check to see if the letters DI are in those columns. If DI is there, the line should be deleted.

Once that is finished, I need to edit the file again and replace anything in columns 3 - 12 with the numbers 0123456789

I hope this makes it a little more clear.
Let me know if you have any suggestions.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Jul 15, 2004 3:42 pm

Modified from the earlier posting:
//Read each line of the old file:
Let>line=0

Label>Start
Let>line=%line%+1
ReadLn>oldfile,%line%,result
If>%result%=##EOF##,End

//Use MidStr to look at certain column positions:
MidStr>%result%,70,1,test

//Use IF to make decisions:
If>%test%=DI,Start

//Replace positions 3-12
MidStr>%result%,1,2,leader
MidStr>%result%,13,1000,trailer

//Use WriteLn to replace lines:
WriteLn>newfile,%leader%0123456789%trailer%
Goto>Start

Label>End
This does both tasks in one pass. It rewrites the oldfile to the newfile, replacing characters 3-12, but only writing lines that do not have DI in positions 70-71. Note that this is untested.

Remember if you use Cut/Paste from the forum to remove trailing spaces. You can do this in the Editor. Click on Edit, Show All Chars, and Remove Trailing Spaces.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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