Sha256: 8e263e2eecbf7d1de4761d7536cb15c401ca73c6e999c106f090e46fc9dd17a9
Contents?: true
Size: 1.01 KB
Versions: 4
Compression:
Stored size: 1.01 KB
Contents
#!/usr/bin/env ruby require "knj/autoload" include Knj begin options = {} OptionParser.new do |opts| opts.banner = "Usage: example.rb [options]" opts.on("-f FINDTHIS", "--find", "Search for this string.") do |f| options[:find] = f end opts.on("-b BYTES", "--bytes BYTES", "Return this number of bytes and finding the string.") do |b| options[:bytes] = b.to_i end opts.on("--filepath FILEPATH", "The file that should be searched.") do |fp| options[:filepath] = fp end end.parse! rescue OptionParser::InvalidOption => e Php.die(e.message + "\n") end cont = "" readstr = "" retcont = "" File.open(options[:filepath], "r") do |fp| loop do break if fp.eof prevcont = String.new(readstr) readstr = fp.read(1024) cont = prevcont + readstr if ind = cont.index(options[:find]) read_size = options[:bytes] - (cont.length - ind) if read_size > 0 cont += fp.read(read_size) end retcont = cont.slice(ind, options[:bytes]) break end end end print retcont + "\n"
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
knjrbfw-0.0.8 | lib/knj/scripts/filesearch.rb |
knjrbfw-0.0.7 | lib/knj/scripts/filesearch.rb |
knjrbfw-0.0.4 | lib/knj/scripts/filesearch.rb |
knjrbfw-0.0.3 | lib/knj/scripts/filesearch.rb |