Sign in to follow this  
Followers 0
blueron

how can I Read the contents after a specific line

3 posts in this topic

Hi,

i need to write a script that can read the entire contents of a text file after a specific line number. .. Say i need to read the contents after the 12th line to all the way down ..I then need to put hat data into another file. how do i go about it ? anyone ? please help. :whistle:

Share this post


Link to post
Share on other sites



Try something like the following untested bit of code:

$Openfile = FileOpen("test1.txt", 0)
$Savefile = FileOpen("test2.txt", 1)

; Check if file opened for reading OK
If $Openfile = -1 Then
    MsgBox(0, "Error", "Unable to open Openfile .")
    Exit
EndIf
; Check if file opened for writing OK
If $Savefile = -1 Then
    MsgBox(0, "Error", "Unable to open Savefile .")
    Exit
EndIf

; Read in lines of text until the EOF is reached
$CurrentLineNumber = 1
While 1
    $line = FileReadLine($Openfile)
    If @error = -1 Then ExitLoop
    If $CurrentLineNumber >= 12 Then
        FileWriteLine($Savefile, $line)
    EndIf
    $CurrentLineNumber = $CurrentLineNumber + 1
WEnd

FileClose($Openfile)
FileClose($Savefile)

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

Hey thanx a lot man .. That worked :whistle: Thank you very much.

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