Skip to content

Instantly share code, notes, and snippets.

@jacobo
Created June 11, 2009 20:46
Show Gist options
  • Save jacobo/128227 to your computer and use it in GitHub Desktop.
Save jacobo/128227 to your computer and use it in GitHub Desktop.
buckets = {}
index = 1
File.open "../test_syslogs/test.syslog.log" do |fp|
fp.each_line do |line|
line =~ / ([^ ]+) ([^ ]+)\[(\d+)\]: (.*)/
next if $2.nil? or $2 == 'newsyslog'
pid = $3
bucket = [$1, $2, $3].join '-'
data = $4
buckets[bucket] ||= [index, []]
buckets[bucket][0] = index
buckets[bucket][1] << data
index += 1
# puts "pid: #{pid} data #{data}"
end
end
buckets.each do |key, index_and_value|
index, value = index_and_value
File.open("test_log_parts/#{'%03i' % index}_#{key}.log", "w+") do |fp|
fp.write(value.join("\n"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment