Jump to content
Sign in to follow this  
bartekd

Find line number in a text file

Recommended Posts

bartekd

I need some help with a loop statement. I have the last line of a text file, but what I want to find out, going backwards from the end of the text file, and ouput the line number that has a certain text.

This is what I have.

$All_linecount = _FileCountLines($logfile) Last line of the text file

If StringInStr(FileReadLine($logfile, $linecount -1), "50") Then ... part of the if statement. I need to loop this, going backwards from the last line until it finds the string 50. If it does find it, I want there to be a variable that is that line number.

Can someone help?

For example, this is what is in the text file. I want it to ouput line 10 (sdfg sd 50)

dfg 50

assd fg

dsdsf sdf

re sdfg

sdfg sd 50 sdfg

dffg

wedfsd

cd gfd s

rtdsg

sdfg sd 50

dfg

dfg

sdfg

sdf

g

sdfg

sdfg

Edited by bartekd

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.