Jump to content
Sign in to follow this  
yucatan

fileread

Recommended Posts

yucatan

hi i have a file with 50 rules and on the 46 rule is standing a variable

i wanne make that i can search to that variable and read that rule how i can do that ?

so if on the 46 is standing hello

that i can enter in a inbox hello and that he is going to search and he found on rule 46 the words hello and then he needs to read that whole line and show it to me how i can do that ?

Share this post


Link to post
Share on other sites
muhmuuh

$word=InputBox("word", "word")
$f=FileOpen("file.txt", 0)
$br=0
While 1
    $l = FileReadLine($f)
    If @error = -1 Then ExitLoop
    $br+=1
    if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br)
Wend
FileClose($f)

;) ?

Edited by muhmuuh

I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more.

Share this post


Link to post
Share on other sites
yucatan

$word=InputBox("word", "word")
$f=FileOpen("file.txt", 0)
$br=0
While 1
    $l = FileReadLine($f)
    If @error = -1 Then ExitLoop
    $br+=1
    if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br)
Wend
FileClose($f)

;) ?

hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ?

Share this post


Link to post
Share on other sites
yucatan

$word=InputBox("word", "word")
$f=FileOpen("file.txt", 0)
$br=0
While 1
    $l = FileReadLine($f)
    If @error = -1 Then ExitLoop
    $br+=1
    if stringinstr($l, $word, 1)<>0 then Msgbox(0, "found", "I found your word in line " & $br)
Wend
FileClose($f)

;) ?

hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ?

p.s. why i cant search @ line 1 he dont find what i search on line one?

its not importend that i know with rule it is.. i just need to be able to read that entire rule that what i need

find the line containing the words i look for and read that entire rule that what i need.

Edited by yucatan

Share this post


Link to post
Share on other sites
Andreik

Try this:

#include <File.au3>

$PATH = InputBox("FILE","Please select path",@ScriptDir & "\file.txt")
$WORD=InputBox("WORD", "Search for word")
$FILE=FileOpen($PATH, 0)
For $INDEX = 1 To _FileCountLines($PATH)
    $LINE = FileReadLine($FILE,$INDEX)
    If StringInStr($LINE,$WORD,1) <> 0 Then Msgbox(0, "FOUND", "I found your word in line " & $INDEX)
Next
FileClose($FILE)

When the words fail... music speaks

Share this post


Link to post
Share on other sites
CrazyGenius

hmm nice but how i can say read that file example now he found that i searched on line 2 how i can say read line 2 ?

p.s. why i cant search @ line 1 he dont find what i search on line one?

Well there are a few ways to do it one is to read and display all lines

$word=InputBox("word", "word")

$f=FileOpen("file.txt", 0)

$br=0

While 1

$l = FileReadLine($f)

If @error = -1 Then ExitLoop

MsgBox(0, "Line read:", $l)

Wend

FileClose($f)

if lines are numbered you can searc the number line instead

$word=InputBox("word", "word")

$f=FileOpen("file.txt", 0)

$br=0

While 1

$l = FileReadLine($f)

If @error = -1 Then ExitLoop

$br+=1

if stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br)

Wend

FileClose($f)

remembering line 1 will be 0 until it runs through the first time

eg file.txt contains

Hi

Moo

Now

$br will go

$br = 0 (Hi)

$br = 1 (Moo)

$br = 2 (Now)

just trial a few ways to search and display

Share this post


Link to post
Share on other sites
yucatan

Well there are a few ways to do it one is to read and display all lines

$word=InputBox("word", "word")

$f=FileOpen("file.txt", 0)

$br=0

While 1

$l = FileReadLine($f)

If @error = -1 Then ExitLoop

MsgBox(0, "Line read:", $l)

Wend

FileClose($f)

if lines are numbered you can searc the number line instead

$word=InputBox("word", "word")

$f=FileOpen("file.txt", 0)

$br=0

While 1

$l = FileReadLine($f)

If @error = -1 Then ExitLoop

$br+=1

if stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br)

Wend

FileClose($f)

remembering line 1 will be 0 until it runs through the first time

eg file.txt contains

Hi

Moo

Now

$br will go

$br = 0 (Hi)

$br = 1 (Moo)

$br = 2 (Now)

just trial a few ways to search and display

nice nice but i only need to search for a rule containing the word i enterd and then it need to read that entire line. thats what i need..

how can i say to filereadline to read line 2 ?

Edited by yucatan

Share this post


Link to post
Share on other sites
Andreik

nice nice but i only need to search for a rule containing the word i enterd and then it need to read that entire line. thats what i need..

how can i say to filereadline to read line 2 ?

FileReadLine($file,2)

When the words fail... music speaks

Share this post


Link to post
Share on other sites
CrazyGenius

FileReadLine($file,2)
theres that too ;)

Share this post


Link to post
Share on other sites
yucatan

FileReadLine($file,2)
h mm okee i see i shall give it a try thx alot peopel.

Share this post


Link to post
Share on other sites
CrazyGenius

h mm okee i see i shall give it a try thx alot peopel.

just remember if you need to make it a variable you will be able to search it like in my second example

if stringinstr($br, $word, 1)<>0 then Msgbox(0, "found", "Contents of line " & $br) ; it will run till $br hits the same number

or you can just go

$word=InputBox("word", "word")

$f=FileOpen("file.txt", 0)

$l = FileReadLine($f,$word)

Msgbox(0, "found", "Contents of line " & $l)

FileClose($f)

and add inputbox to get a user typed file there are many ways to go about it

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  

×