My GPS logger periodically leaves "incomplete" lines at the end of the log files. I think they are only at the end, but I want to check all the lines just in case.
The full sentence of the offer looks like this:
$GPRMC,005727.000,A,3751.9418,S,14502.2569,E,0.00,339.17,210808,,,A*76
The string must begin with the $ character and end with the * character and a two-character hexadecimal checksum. I do not care about the correctness of the checksum, just that it is present. It is also necessary to ignore the "ADVER" clauses, which do not have a checksum and are located at the beginning of each file.
The following Python code may work:
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)
Is there a way to do this with grep or awk or something simple? I really didn't understand how to get grep to do what I want.
Update : thanks @Motti and @Paul, I was able to do the following to do almost what I wanted, but had to use single quotes and remove the trailing $ before it would work
grep -nvE '^\$.*\*[0-9A-F]{2}' *.log | grep -v ADVER | grep -v ADPMB
Two more questions arise: how can I ignore empty lines? And can I combine the last two grep s?