Makistos
12/15/2016 - 8:07 AM

Remove timestamps and process numbers from Android (both kernel and logcat). This makes it easier to compare logs in e.g. Beyond Compare. #p

Remove timestamps and process numbers from Android (both kernel and logcat). This makes it easier to compare logs in e.g. Beyond Compare. #perl #android

#!/usr/bin/perl

# Clean up Android logs so that they are easier to compare.

while(<>)
{
    if (m/^\[/) {
        # Captured from UART
        if (m/^\[.+\]\s\d\d-\d\d/) {
            # Logcat
            $_ =~ s/^\[.+\]\s\d\d-\d\d\s(\d\d:*){3}\.\d{3}\s+\d+\s+\d+\s(.+)/$2/;
        } else {
            # Kernel
            $_ =~ s/^(\[.+\])*\s(\[.+\])\s+(.+)/$3/;
        }
    } elsif (m/(\d\d:*){3}\.\d{3}\s\<\d\>/) {
        # Kernel
        $_ =~ s/^((\d\d:*){3}\.\d{3}\s)(\<\d\>)(\[\d+\.\d+\])*\s*(.+)/$5/;
    } else {
        # Logcat
        $_ =~ s/^((\d\d:*){3}\.\d{3})\s(.+)\(\s*\d+\)(.+)/$3 $4/;
    }
    print;
}