Wednesday, March 9, 2011

pick the ips out of a big ugly text file using tcl 8.5.9 tclsh

# cat grabip.tcl
#!/usr/local/bin/tclsh

## Read the file
set fid [open 144a]
set content [read $fid]
close $fid

## Split into records on 1 blank space
set records [split $content " "]

#open result file
set chan [open 144list a]

#pick out ips on 144 network such as 144.123.123.123 etc. and write them to result file
foreach rec $records {
if {[string match {144*[1-9]} $rec]} {
puts $chan $rec
}
}

#close result file
close $chan

No comments: