3 ms·
I still use perl for handy one liners on the command line. E.g. I had a 1 GB log file where I wanted to generate a histogram of the intervals between certain lo
by gkfasdfasdf 7y ago
I still use perl for handy one liners on the command line. E.g. I had a 1 GB log file where I wanted to generate a histogram of the intervals between certain log messages. I used a perl one-liner to extract the timestamp via regex (regexs are perl's bread and butter), calculate the diff between the previous timestamp (easy because of auto string => double conversion), use the diff value as a key in a hash of counters (autovivification really handy here), then print the hash at the end with sorted keys using the Data::Dumper module. Took me all of 5 minutes to write. I don't write Perl often but I am thankful that it exists.
- markoman 7y agoI'm an occasional perler myself and I bet that others or myself would find that code you mention to be useful, at least for the black book of snippets. Would you mind pasting?
- gkfasdfasdf 7y agoHere is the command I used (added linebreaks for clarity): rg '<filter pattern>' <logfile> | \ perl -MData::Dumper -n -e ' m/\d{2}:\d{2}:([\d.]+)/; if ($last) { $diff = $1 - $last; print "$diff\n"; $hist{$diff} += 1; } $last = $1; END { $Data::Dumper::Sortkeys = true; print Dumper(\%hist); } '