Added line counting
This commit is contained in:
parent
79329520e2
commit
233e33348d
17
main.go
17
main.go
@ -20,16 +20,26 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
|
split := &Splitter{}
|
||||||
scan := bufio.NewScanner(file)
|
scan := bufio.NewScanner(file)
|
||||||
scan.Split(Split)
|
scan.Split(split.Split)
|
||||||
for scan.Scan() {
|
for lastline := 0; scan.Scan(); {
|
||||||
|
if lastline < split.Line {
|
||||||
|
lastline = split.Line
|
||||||
|
fmt.Printf("\n")
|
||||||
|
}
|
||||||
word := scan.Text()
|
word := scan.Text()
|
||||||
fmt.Printf("[%s] ", word)
|
fmt.Printf("[%s] ", word)
|
||||||
}
|
}
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Split(data []byte, atEOF bool) (int, []byte, error) {
|
|
||||||
|
type Splitter struct {
|
||||||
|
Line int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sp *Splitter) Split(data []byte, atEOF bool) (int, []byte, error) {
|
||||||
var ignoreline bool
|
var ignoreline bool
|
||||||
var started bool
|
var started bool
|
||||||
var startidx int
|
var startidx int
|
||||||
@ -39,6 +49,7 @@ func Split(data []byte, atEOF bool) (int, []byte, error) {
|
|||||||
c := data[i]
|
c := data[i]
|
||||||
switch c {
|
switch c {
|
||||||
case '\f', '\n', '\r':
|
case '\f', '\n', '\r':
|
||||||
|
sp.Line++
|
||||||
if ignoreline {
|
if ignoreline {
|
||||||
return i + 1, nil, nil
|
return i + 1, nil, nil
|
||||||
}
|
}
|
||||||
|
2
small.config
Normal file
2
small.config
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Address is optional, derived from host
|
||||||
|
monitor host monkey.com
|
Loading…
Reference in New Issue
Block a user