Created
June 11, 2009 20:46
-
-
Save jacobo/128227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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