Sha256: 8bb8a1fd9e89d74b3bbcee6acb1afbf18ef1ea1f31ab33b6d97fc45f3047bda3
Contents?: true
Size: 1 KB
Versions: 52
Compression:
Stored size: 1 KB
Contents
#!/usr/bin/env ruby # # Copyright (C) 2004 Satoru Takabayashi <satoru@namazu.org> # You can redistribute it and/or modify it under GPL2. # puts "Usage: tdiary-referer-clean PATTERN FILE..." if ARGV.length == 0 pattern = Regexp.new(ARGV.shift) file_names = ARGV deleted_referers = [] file_names.each {|file_name| tmp_name = "tmp.#{Process.pid}" i = File.open(file_name) o = File.open(tmp_name, "w") first_line = i.gets o.print first_line while true date_line = i.gets break if date_line.nil? raise unless /^Date: /.match(date_line) blank_line = i.gets raise unless blank_line == "\n" o.print date_line o.print blank_line while line = i.gets if line == ".\n" o.print line next end if pattern.match(line) deleted_referers.push(line) else o.print line end end end i.close o.close File.rename(file_name, file_name + ".bak") File.rename(tmp_name, file_name) } deleted_referers.each {|referer| print referer }
Version data entries
52 entries across 46 versions & 2 rubygems