example.. say I have a file that contains the following information
Ted 250
John 291
Bill 301
How can I READ this file and say, I only want to match the line that contains matching text to TED -- thus it would output 'Ted 250'
Please help

Code: Select all
# Set the path and filename of text file to read
set file2read "you/need/to/edit/this/path/file_to_read.txt"
bind pub - "!readfile" readfile
proc readfile {nick uhost handle chan text} {
global file2read
if {![file exists $file2read]} {
putserv "privmsg $chan :Sorry, $file2read does not exist"
} else {
set fname "$file2read"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
if {[lsearch -exact -nocase -inline -all -index 0 $lines $text] != ""} {
putserv "privmsg $chan :[join [lsearch -exact -nocase -inline -all -index 0 $lines $text]]"
} else {
putserv "privmsg $chan :Sorry, $text not found"
}
}
}
putlog "Please see: http://forum.egghelp.org/viewtopic.php?t=18428"
# ref: http://forum.egghelp.org/viewtopic.php?t=6885
# http://www.tcl.tk/man/tcl8.5/TclCmd/lsearch.htm