|
|
|
| im looking for a script that can extract hostnames from a
list(txt,html) like this:
the-roadside.com 3 43197 1( 0)
202.218.17.12-OK
adsvr1.emome.net 25 3391 1( 0)
211.79.36.59-OK
ads.b10f.jp 44 2104 1( 0)
58.4.47.114-OK
ads.topfong.com 46 79977 3( 0)
61.63.4.232-OK 61.63.4.231-OK 61.63.4.230-OK
adspic.topfong.com 46 79978 1( 0)
61.63.4.242-OK
adstat3.kkman.com.tw 53 59 1( 0)
210.200.247.112-OK
ads.pointroll.com 186 48 1( 0)
66.216.104.176-OK
global.m s.net 287 -57 2( 0)
210.201.139.93-OK 80.81.66.93-OK
ads.veryhuman.com 712 83084 1( 0)
219.84.160.198-OK
| |
| Michael A. Cleverly 2006-09-29, 4:08 am |
| On Thu, 28 Sep 2006, tom wrote:
> im looking for a script that can extract hostnames from a
> list(txt,html) like this:
>
> the-roadside.com 3 43197 1( 0)
> 202.218.17.12-OK
> [etc...]
set hosts [list]
set fp [open path/to/the/file]
while {[gets $fp line] != -1} {
lappend hosts [lindex $line 0]
}
close $fp
puts $hosts
Michael
| |
| Gerald W. Lester 2006-09-29, 4:08 am |
| Michael A. Cleverly wrote:
> On Thu, 28 Sep 2006, tom wrote:
>
>
> set hosts [list]
> set fp [open path/to/the/file]
> while {[gets $fp line] != -1} {
> lappend hosts [lindex $line 0]
> }
> close $fp
> puts $hosts
>
> Michael
You really should do a split on the input -- just in case it is not a proper
list, thus:
lappend hosts [lindex [split [string trim $line]] 0]
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
| |
| slebetman@yahoo.com 2006-09-29, 4:08 am |
| tom wrote:
> im looking for a script that can extract hostnames from a
> list(txt,html) like this:
>
> the-roadside.com 3 43197 1( 0)
> 202.218.17.12-OK
> adsvr1.emome.net 25 3391 1( 0)
> 211.79.36.59-OK
While the (ab)use of list functions work here's a version I prefer
using string functions:
while {[gets $fp line] != -1} {
set line [string trim $line]
lappend hosts [string trim [string range $line 0 [string wordend
$line 0]]]
}
| |
| Bryan Oakley 2006-09-29, 8:03 am |
| Michael A. Cleverly wrote:
> On Thu, 28 Sep 2006, tom wrote:
>
>
>
>
> set hosts [list]
> set fp [open path/to/the/file]
> while {[gets $fp line] != -1} {
> lappend hosts [lindex $line 0]
> }
> close $fp
> puts $hosts
>
> Michael
That only works if the data is guaranteed to be a well-formed series of
newline separated tcl lists. Real world data is notorious for being
ignorant of that requirement.
--
Bryan Oakley
http://www.tclscripting.com
|
|
|
|