-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrandomized2
More file actions
executable file
·51 lines (42 loc) · 749 Bytes
/
Copy pathrandomized2
File metadata and controls
executable file
·51 lines (42 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
def usage
$stderr.puts("Usage: #{File.basename($0)} <lines> <filename>")
exit(1)
end
parameters = []
options = []
verbose = false
ARGV.each do |arg|
if arg[0] == '-'
options << arg
else
parameters << arg
end
end
if parameters.length != 2 then
usage()
end
options.each do |option|
case option
when '-v'
verbose = true
when '-h'
usage()
end
end
lines = parameters[0].to_i
filename = parameters[1]
if lines < 1
$stderr.puts("at least one line please")
exit(1)
end
filesize = File.size(filename)
File.open(filename) do |f|
for i in 0...lines
start = i * filesize / lines
position = start + rand(filesize / lines)
f.pos = position - 1
f.gets
puts f.gets
end
end