Sign in to follow this  
Followers 0
locutus243

FileRead Variable

7 posts in this topic

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

Share this post


Link to post
Share on other sites



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
See

This topic as it appears to be a similar request.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


Link to post
Share on other sites

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...)

Share this post


Link to post
Share on other sites

May I ask what you want it to do after it reads the 3rd line after it?


[center]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.[/center]

Share this post


Link to post
Share on other sites

I'm using it as a lookup. I have a text file as in the example below:-

12/01/2006 11:04:40

700

Season: 113 WG: 16.26.700

Item No: 20H640 failed due to No Net Estimate

E-Mail Sent to Sam Quigley

Unresolved

12/01/2006 11:04:46

814

Season: 113 WG: 16.26.700

Item No: 19J760 failed due to No Net Estimate

E-Mail Sent to Sam Quigley

Unresolved

12/01/2006 11:04:46

650

Season: 113 WG: 16.26.700

Item No: 20J445 failed due to No Net Estimate

E-Mail Sent to Sam Quigley

Unresolved

12/01/2006 11:04:46

650

Season: 113 WG: 16.26.700

Item No: 19J760 failed due to No Net Estimate

E-Mail Sent to Sam Quigley

Unresolved

As 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

Share this post


Link to post
Share on other sites

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.


[center]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.[/center]

Share this post


Link to post
Share on other sites

Cheers Smoke, seems to work a treat.

Much appreciated

Mark

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0