Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 085959d52c
Fetching contributors…

Cannot retrieve contributors at this time

executable file 33 lines (27 sloc) 0.833 kb
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
#!/usr/bin/env ruby
# Make replay log by extracting the URI from an Apache CLF log file
# replacing string 'match' by 'substitute' and concatenating them
# together by replacing \n by \0

progname = File.basename($0)

if ARGV.size < 2
  puts "Usage: ruby #{progname} 'match' 'substitute' file1 [file2 [file3]] > output_file"
  puts "Usage: cat logfile | ruby #{progname} 'match' 'substitute' > output_file"
  puts
  puts "Example: cat /var/log/access_log | ruby #{progname} '/app' '/' > replay_log"
  exit
end

match = ARGV.shift
sub = ARGV.shift

ARGF.each do |line|
  request = line.split('"')[1]
  next if request.nil?
  
  uri = request.split[1]
  next if uri.nil?
  
  begin
    uri[match] = sub
  rescue IndexError
    # simply output line that don't contain the 'replace' string
  ensure
    print uri.chomp + "\0"
  end
end
Something went wrong with that request. Please try again.