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.

first/last line

Old posts that have not been replied to for several years.
Locked
m
micky
Voice
Posts: 11
Joined: Mon Dec 13, 2004 10:07 am

first/last line

Post by micky »

Someone write script like this:

cmd: .s FIRST LAST

Code: Select all

FIR
text1
text2
text3
FIRST
text4
text5
text6
LAST
text7
text8
text9
NEXT
[...]
script return:
text4
text5
text6
all between FIRST and LAST.
Thx for help
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

Code: Select all

proc s { w f l } {
  set fp [open $w r] ; set d [split [read $fp] \n] ; close $fp
  set r [lrange $d [expr {[lsearch $d $f]+1}] [expr {[lsearch $d $l]-1}]]
}
% s <file> FIRST LAST
text4 text5 text6
obviously you'd also check to see if file exists/readable (if you're reading from a file), and you should check if the lsearch fails
photon?
m
micky
Voice
Posts: 11
Joined: Mon Dec 13, 2004 10:07 am

Post by micky »

but "file" is:

Code: Select all

FIR 
random text1 
random text2 
random text3 
FIRST 
random text4 
random text5 
random text6 
LAST 
random text7 
random text8 
random text9 
NEXT 
[...] 
and i need to write to channel:
nick: .s FIRST LAST
bot: random text4
bot: random text5
bot: random text6
:)
thx for help:)
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

Code: Select all

set somestring "FIR\nrandom1\nrandom2\nrandom3\nFIRST\nrandom4\nrandom5\nrandom6\nLAST\nrandom7\netc"

bind pub n .s pub:s
proc pub:s { n u h c t } {
  if {[llength [split $t]] != 2} { puthelp "PRIVMSG $c :usage: .s <first> <last>" ; return }
  if {[set result [s [lindex [split $t] 0] [lindex [split $t] 1]]] != "ERROR" } {
    foreach l $result { puthelp "PRIVMSG $c :$l" }
    return
  }
  puthelp "PRIVMSG $c :$result"
  return
}

proc s { f l } {
  set d [split $::somestring \n] ;# set d $::somestring (if it's a list)
  if {[set f [lsearch $d $f]] != -1 && [set l [lsearch $d $l]] != -1} {
    set r [lrange $d [expr {$f+1}] [expr {$l-1}]]
  } { return ERROR }
}
<you> .s FIRST LAST
<bot> random4
<bot> random5
<bot> random6

can also use wildcards
<you> .s *IRS* *AST
<bot> random4
<bot> random5
<bot> random6
photon?
m
micky
Voice
Posts: 11
Joined: Mon Dec 13, 2004 10:07 am

Post by micky »

very thx!:)
Locked