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.

Grabbing a certain line on a file?

Old posts that have not been replied to for several years.
Locked
P
Pyr0
Voice
Posts: 20
Joined: Sun Jan 05, 2003 9:20 pm

Grabbing a certain line on a file?

Post by Pyr0 »

Code: Select all

proc dj {nick host hand chan arg} {
     global radio_url listener kbps song mlister
     set file [open "|lynx http://64.246.38.123:9061/admin.cgi?pass=passgoeshere&mode=viewxml" r] 
     set html "[gets $file]"
But I have no clue what to do next. I want it to grab the 16th line on the xml file which is like <AIM>name</AIM> and use regsub to remove the <> tags. But I have no clue on how to grab the 16th line.
Any ideas?[/code]
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

there is several ways of doing this...
one is to use lsearch or string match on it,, the pull out the elements...etc
another is to use string trim left/right , then you will be left with just the chars between <aim> and </aim> .... hopefully ;)
Elen sila lúmenn' omentielvo
P
Pyr0
Voice
Posts: 20
Joined: Sun Jan 05, 2003 9:20 pm

Post by Pyr0 »

if {[string match "<AIM>*" $line]} {
regsub -all "<AIM>" $line "" line
regsub -all "</AIM>" $line "" line
putserv "PRIVMSG $chan : $line"
}

I tried that but it didn't work. Outputted blank if I remember.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

As noted in the reply, use "string trimleft" and "string trimright", and not regsub.

Regsub uses regular expressions, which can be used for this, but would need escaping.
P
Pyr0
Voice
Posts: 20
Joined: Sun Jan 05, 2003 9:20 pm

Post by Pyr0 »

Code: Select all

     set file [open "|lynx -source http://64.246.38.123:9061/admin.cgi?pass=pass&mode=viewxml" r] 
     set html $file
     set html "[string trimleft html "<AIM>"]"
     set html "[string trimright html "</AIM>"]"
     putserv "PRIVMSG $chan : 9,1\[\ \0030Your current DJ:\002 $html \002\0039\]"\
It returns "html" =/.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

hehe I think it would help if you put $ infront of html ;)
Elen sila lúmenn' omentielvo
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

[quote="Pyr0"]

Code: Select all

     set file [open "|lynx -source http://64.246.38.123:9061/admin.cgi?pass=pass&mode=viewxml" r] 
     set html $file
     set html "[string trimleft html "<AIM>"]"
     set html "[string trimright html "</AIM>"]"
     putserv "PRIVMSG $chan : 9,1\[\ \0030Your current DJ:\002 $html \002\0039\]"\
[quote]

There are many issues here.

1: You are using "html" instead of "$html" in the "strign trim*" commands.

2: You have made the putserv line over complicated, with a mixture of real CTRL characters, excape codes and unrequired escape codes

3: You are using the return value from the "open" command, to set a variable. You then set "$html" to the same value as returned from "open". The "open" command returns a channel number/file pointer, which is used in command such as read, gets, puts, fconfigure and other socket and file commands.
Locked