File tree 1 file changed +7
-2
lines changed 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ import (
10
10
)
11
11
12
12
func main () {
13
-
13
+ var total int64
14
+ var emitted int64
14
15
if len (os .Args ) != 2 {
15
16
fmt .Fprintf (os .Stderr , "invalid argument. use a fraction to sample between 0.0 (no sampling) and 1.0 (100% sampling)" )
16
17
os .Exit (1 )
@@ -25,13 +26,17 @@ func main() {
25
26
rand .Seed (time .Now ().UnixNano ())
26
27
scanner := bufio .NewScanner (os .Stdin )
27
28
for scanner .Scan () {
29
+ total += 1
28
30
if target < rand .Float64 () {
29
31
continue
30
32
}
33
+ emitted += 1
31
34
fmt .Printf ("%q" , scanner .Text ()) // Println will add back the final '\n'
32
35
}
33
36
if err := scanner .Err (); err != nil {
34
- fmt .Fprintln (os .Stderr , "reading standard input:" , err )
37
+ fmt .Fprintln (os .Stderr , "Error reading standard input:" , err )
35
38
os .Exit (2 )
36
39
}
40
+
41
+ fmt .Fprintf (os .Stderr , "Total of %d lines. Sampled to %d\n " , total , emitted )
37
42
}
You can’t perform that action at this time.
0 commit comments