locutus243 Posted January 12, 2006 Share Posted January 12, 2006 Hiya guys, I'm reading from a text file and I want my script to read a line, and at the same time read the line which is 3 lines after it. I've been at it all morning and can't seem to crack the problem. I've tried using a variable $count in a While function but it doesn't seem to read the variable properly cos it aint working. I've included my script below to hopefully shed some light. Any help greatly appreciated Mark $count = 0 Do $line = FileReadLine($file) & StringMid(FileReadLine($file, $count + 3), 10, 6) $count = $count + 1 Until $line = $FindPub & $FindItem Link to comment Share on other sites More sharing options...
BigDod Posted January 12, 2006 Share Posted January 12, 2006 Hiya guys, I'm reading from a text file and I want my script to read a line, and at the same time read the line which is 3 lines after it. I've been at it all morning and can't seem to crack the problem. I've tried using a variable $count in a While function but it doesn't seem to read the variable properly cos it aint working. I've included my script below to hopefully shed some light. Any help greatly appreciated Mark $count = 0 Do $line = FileReadLine($file) & StringMid(FileReadLine($file, $count + 3), 10, 6) $count = $count + 1 Until $line = $FindPub & $FindItemSee This topic as it appears to be a similar request. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
locutus243 Posted January 12, 2006 Author Share Posted January 12, 2006 Similar perhaps but I am not looking to return all the different instances that something appears in the text file. I am simply looking to read a line and then a line which is 3 ahead of it. (For example read line 1 & 4, 2 & 5, 3 & 6 etc...) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2006 Moderators Share Posted January 12, 2006 May I ask what you want it to do after it reads the 3rd line after it? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
locutus243 Posted January 12, 2006 Author Share Posted January 12, 2006 I'm using it as a lookup. I have a text file as in the example below:-12/01/2006 11:04:40700Season: 113 WG: 16.26.700Item No: 20H640 failed due to No Net EstimateE-Mail Sent to Sam QuigleyUnresolved12/01/2006 11:04:46814Season: 113 WG: 16.26.700Item No: 19J760 failed due to No Net EstimateE-Mail Sent to Sam QuigleyUnresolved12/01/2006 11:04:46650Season: 113 WG: 16.26.700Item No: 20J445 failed due to No Net EstimateE-Mail Sent to Sam QuigleyUnresolved12/01/2006 11:04:46650Season: 113 WG: 16.26.700Item No: 19J760 failed due to No Net EstimateE-Mail Sent to Sam QuigleyUnresolvedAs you can see it is a problem log and each problem has its own section. I want to be able to lookup a certain section (which needs to be using both Publication (e.g. 650) and Item Number) and then when it finds the publication to edit the unresolved so that it reads resolved when the problem has been sorted. I've tried using _FileReadToArray but I need the line number that the item number appears on so I can begin to work out how to edit the 'unresolved' bit. I'm not even sure if its possible to edit a text file like this???Anyways, hope this explains what I'm trying to do and makes my problem a bit clearer. Again, any help is much appreciated.Mark Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2006 Moderators Share Posted January 12, 2006 I did this quick but.. you may be able to use a StringInStr() option to mod this a bit... I've got a splitting headache, so I can't really understand exactly what you want to do if something is found, or I would have added it in here.#include <File.au3> $FILE = FileOpenDialog('Open File To Read', @ScriptDir, 'All Text Files (*.txt)') $OutPut = StringTrimRight($FILE, 4) & '_Edited.txt' GetLineAndThree($FILE, $OutPut) Func GetLineAndThree($f_File, $o_OutPutFile) Local $nArray Local $LineToReadAndThirdLine _FileReadToArray($f_File, $nArray) For $i = 1 To UBound($nArray) - 1 Local $TotalLinesRead = UBound($nArray) - 1 If $i < $TotalLinesRead - 2 Then $LineToReadAndThirdLine = $LineToReadAndThirdLine & $nArray[$i] & @CRLF & $nArray[$i+3] & @CRLF & @CRLF Else ExitLoop EndIf Next FileWriteLine($o_OutPutFile, $LineToReadAndThirdLine) EndFunc Right now it Takes the current line your on, then moves down 3 lines, and will write the line your on and the 3rd line under it... when you get to 2 from the bottom of the file it stops. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
locutus243 Posted January 13, 2006 Author Share Posted January 13, 2006 Cheers Smoke, seems to work a treat. Much appreciated Mark Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now