summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-02-14 22:22:35 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-02-14 22:30:55 (GMT)
commitfa133fb4f4e59651066d3451dcb9917b4176c1fb (patch)
treebe25bf2a550e685fab7be9181c6661e474dc50d2
parentf367f0a6c5fdee0dbf6ccc97051307f17d08914f (diff)
downloadmisc-fa133fb4f4e59651066d3451dcb9917b4176c1fb.zip
misc-fa133fb4f4e59651066d3451dcb9917b4176c1fb.tar.gz
misc-fa133fb4f4e59651066d3451dcb9917b4176c1fb.tar.bz2
meme/log2marker.pl: helper script to convert meme logs to markers
Saves a lot of tedious copy & paste.
-rwxr-xr-xmeme/log2mark.pl80
1 files changed, 80 insertions, 0 deletions
diff --git a/meme/log2mark.pl b/meme/log2mark.pl
new file mode 100755
index 0000000..d46a956
--- /dev/null
+++ b/meme/log2mark.pl
@@ -0,0 +1,80 @@
+#!/usr/bin/perl
+#
+# log2mark - Convert meme log output to markers
+#
+# Written 2016 by Werner Almesberger
+# Copyright 2016 by Werner Almesberger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+
+
+sub usage
+{
+ print STDERR <<"EOF";
+usage: $0 [-f] tag [file ...]
+
+ -f follow file (like tail -f)
+EOF
+ exit(1);
+}
+
+
+while ($ARGV[0] =~ /^-./) {
+ if ($ARGV[0] eq "-f") {
+ $follow = 1;
+ } else {
+ &usage;
+ }
+ shift @ARGV;
+}
+
+$field = shift @ARGV;
+&usage unless defined $field;
+
+if ($follow) {
+ $in = shift @ARGV;
+ open(IN, $in) || die "$in: $!" if defined $in;
+}
+
+$d = 0;
+while (1) {
+ if (!defined $in) {
+ $_ = <>;
+ exit unless defined $_;
+ } else {
+ $_ = <IN>;
+ if (!defined $_) {
+ exit unless $follow;
+ close IN;
+ open(IN, $in) || die "$in: $!" if defined $in;
+ }
+ }
+
+ chop;
+
+ $d = /^D:/ if /^\S/;
+ if (/^([AB]):\s+X\s+(\S+)\s+Y\s+(\S+)/) {
+ if ($1 eq "A") {
+ @a = ($2, $3);
+ } else {
+ @b = ($2, $3);
+ }
+ next;
+ }
+ next unless $d;
+ /\S*\s+/;
+ $tag = undef;
+ for (split(/\s+/, $')) {
+ if (defined $tag) {
+ print "$a[0]\t$a[1]\t$b[0]\t$b[1]\t$_\n"
+ if $tag eq $field;
+ undef $tag;
+ } else {
+ $tag = $_;
+ }
+ }
+}