Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I find broken NMEA log sentences with grep?
    text
    copied!<p>My GPS logger occassionally leaves "unfinished" lines at the end of the log files. I think they're only at the end, but I want to check all lines just in case. </p> <p>A sample complete sentence looks like:</p> <pre><code>$GPRMC,005727.000,A,3751.9418,S,14502.2569,E,0.00,339.17,210808,,,A*76 </code></pre> <p>The line should start with a <code>$</code> sign, and end with an <code>*</code> and a two character hex checksum. I don't care if the checksum is correct, just that it's present. It also needs to ignore "ADVER" sentences which don't have the checksum and are at the start of every file.</p> <p>The following Python code might work: </p> <pre><code>import re from path import path nmea = re.compile("^\$.+\*[0-9A-F]{2}$") for log in path("gpslogs").files("*.log"): for line in log.lines(): if not nmea.match(line) and not "ADVER" in line: print "%s\n\t%s\n" % (log, line) </code></pre> <p>Is there a way to do that with <code>grep</code> or <code>awk</code> or something simple? I haven't really figured out how to get <code>grep</code> to do what I want.</p> <p><strong>Update</strong>: Thanks @Motti and @Paul, I was able to get the following to do almost what I wanted, but had to use single quotes and remove the trailing <code>$</code> before it would work:</p> <pre><code>grep -nvE '^\$.*\*[0-9A-F]{2}' *.log | grep -v ADVER | grep -v ADPMB </code></pre> <p>Two further questions arise, how can I make it ignore blank lines? And can I combine the last two <code>grep</code>s?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload