This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

search a specific word in a Text file ...

Old posts that have not been replied to for several years.
Locked
C
CoBrEtTi

search a specific word in a Text file ...

Post by CoBrEtTi »

hi @ ll


1. i`m a newbie in tcl coding ... :-?
2. my englisch is very very bad.. so .. :o

3. i spent a lot of time to do a script, that search a specific word in a text file and post specific lines from the text file...

the text file looks like:

line1
line2
line3
line4

line1
line2
line3
line4


the lines are full sentences ....


so.. my problem is that the script that i found it in this forum post me all, and i need that the script post me, from the first line to the last line (line1 to line4), if the specific word is in line1 or line2 or line3 or line4

the script what i use is a script coded by IsP ..

Code: Select all

 proc rlslocate {nick uhost handle type arg} { 
global rlsmaxsearch cd_release rlsinfo 
if {$arg == ""} {puthelp "$type $nick :Syntax: $cmdsearch <search string>" ;return 0} 
regsub -all -- " " ${arg} "*" rlsarg 
puthelp "$type $nick : $rlsinfo ...Searching for '$rlsarg'" 
set totrlsfound 0 
foreach database $cd_release { 
set rlsfile [open $database r] 
while {![eof $rlsfile]} { 
set rlsline [gets $rlsfile] 
if {[string match "*$rlsarg*" [string tolower $rlsline]]} { 
incr totrlsfound 1 
if {$totrlsfound < $rlsmaxsearch} { 
puthelp "$type $nick : \002Found:\002 $rlsline" 
} 
} 
} 
close $rlsfile 
} 
.
.
.

so i think that the problem/ is in this sniped code, if sb need the code i can send a pm..

thx @ ll for help :roll:


PS: my own script it doesen`t work like IsP script ..so its much easier to take this script ... i think so :oops:
C
CoBrEtTi

Post by CoBrEtTi »

hi,

who can help me ?

I read the FAQ, in the forum and i use also the search function,
but nothing help me, because the post are not in in this example:

<botnick>line1
<botnick>line2
<botnick>line3
<botnick>line4
<botnick>line5
.
.
.


and thats the problem !!

SO, please help me to get this script runnig!

Thx
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

try this:

Code: Select all

proc findParagraph {file what} {
	set f [open $file]
	set data [read -nonewline $f]
	close $f
	# replace two or more linebreaks with a nullbyte:
	regsub -all {\n{2,}} $data \0 data
	# split the resulting string on those nullbytes and loop through
	# the blocks of text to find the first matching one and return it.
	foreach P [split $data \0] {
		if {[string match *$what* $P]} {
			return $P
		}
	}
	# if no matches were found, nothing is returned :P
}
Have you ever read "The Manual"?
C
CoBrEtTi

Post by CoBrEtTi »

tnx user for your help.. :D


i use now this code:

Code: Select all

bind pub - !find pub:find

proc pub:find {n h c a text} {
set a *[string map  {" " *} $a]
set db [open pw.txt]
set data [read -nonewline $db]
close $db

regsub -all {\n{2.}} $data \0 data

foreach found [split $data \0 ] {
  if {[string match *$a* $found]} {
    return $found
  }
  
 }


putserv "PRIVMSG $c :$found"
}
putlog " i love it "
and i get this error on my partyline after trigering for Example !find MGM


[03:09] Userfile loaded, unpacking...
[03:09] Tcl error [pub:find]: couldn't compile regular expression pattern: invalid repetition count(s)
many thx for help... :roll:
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

user wrote:

Code: Select all

regsub -all {\n{2,}} $data \0 data
you wrote:

Code: Select all

regsub -all {\n{2.}} $data \0 data
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
C
CoBrEtTi

Post by CoBrEtTi »

hi,

tnx arcane for the mistake it is a , and not a . i think i need glasses!

So, but the script find nothing or postet nothing.. and i am a bloody beginner in this code.. so who can help me to make this code runnig.

In the partyline are no errors!!


tnx :roll:
C
CoBrEtTi

Post by CoBrEtTi »

hi,

who can help me.. ?? The bot (script) find nothing !!


tnx CoBrEtTi
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

by returning from inside the foreach loop when there's a match, the putserv below will not be executed. Either send the message before you return at that point, keep my code as a separate proc or 'break' out of the loop (if you use break, you'll need code to avoid returning the last line if there's no matches)
Have you ever read "The Manual"?
Locked