Sign in to follow this  
Followers 0
cypher175

How Can I Copy Specific Lines of Text to Another File..?

7 posts in this topic

Is there anyway to Copy Specific Lines of text from a .txt file into Another txt. File..??

Share this post


Link to post
Share on other sites



Any body know..??

Share this post


Link to post
Share on other sites

Wait at least 24 hours before bumping your own topic/thread.

It is best to spend more time on you original post. One single sentence is rarely enough info for us to know what you need/want in the say of help. In this case, do you know the line number of the info to be copied or are you going to have to look for info on each line to determine if it should be copied?


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I just need to copy all the lines of text after line 10 in a text file to another text file..

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I just need to copy all the lines of text after line 10 in a text file to another text file..

I noticed you have over 100 posts so I'm assuming you've tried already...

Look at

$ReadFile = "C:\File to Read.txt"
$WriteFile = "C:\File to Write.txt"
$Max = _FileCountLines($ReadFile)
For $N = 10 to $Max Step 1
     _FileWriteToLine($WriteFile,$N,FileReadLine($ReadFile,$N))
Next
MsgBox(0,"Done","File is done...")

NOT TESTED!! But should give you a good start?

I hope this has helped, I usually don't try helping someone else... I'm usually asking the questions... lol

Edited by BinaryBrother

Share this post


Link to post
Share on other sites

I just need to copy all the lines of text after line 10 in a text file to another text file..

The fast method:

$sFile = @ScriptDir & "\test.txt"
$sRead = FileRead($sFile)

$aStrings = StringSplit($sRead, @CRLF, 1)

If $aStrings[0] < 11 Then Exit

$sResult = ""

For $i = 11 To $aStrings[0]
    $sResult &= $aStrings[$i] & @CRLF
Next

$hFile = FileOpen(@ScriptDir & "\result.txt", 2)
FileWrite($hFile, $sResult)
FileClose($hFile)

:)

Share this post


Link to post
Share on other sites

I just need to copy all the lines of text after line 10 in a text file to another text file..

Well, why didn't you say that in the firstplace? :-) :-) :-)

@BinaryBrother,

Just an FYI to explain a bit more about why rasim said "The fast method:"

From the help file on FileReadLine:

From a performance standpoint it is a bad idea to read line by line specifying "line" parameter whose value is incrementing by one. This forces AutoIt to reread the file from the beginning until it reach the specified line.

I'm not critizing your code, just informing.


[size="1"][font="Arial"].[u].[/u][/font][/size]

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