I am writing a script that is supposed to search trough a file on the server and check if a string given by the user exists in it, if so, it should output it. So far, with the help of greenbear on IRC I got this:
set query [lrange $text 1 end]
set query [string map {" " "\*"} $query]
set srcdb [open users.txt r]
set data [read -nonewline $srcdb]
close $srcdb
set lines [split $data "\n"]
foreach line $lines {
if {[string match -nocase "*$query*" $line]} {
putmsg $chan $line
} else {
}
}
However it does not output any results even if I try it with a query I'm 100% sure is in the database. What am I missing here ?
2 questions:
- why do you use lrange? it looks pointless in your script, since it a) uses a list operation on a string and b) ignores the first entry. esspially the functionality b) could be the cause of your "little problem" .
- why do you escape the *? there is no need to . Another tip... if files always have 1 "whitespace" character, you might want to use ? instead of * depending on the exactness the result should be .