I have a problem with awk that I can’t seem to solve.
I get snmp data from my router to view data usage. this is a text file that is replaced every 24 hours and file is updated every hour. I get a negative number that shows up and it skews the data on my little web server.
I see counter wrap-around (e.g., a 32-bit counter reaching its maximum value and resetting to zero). Weird. The following command seems to solve it you can hide the values if this happens:
cat 08-May-25-wrls0ta.txt | python3 -c $'import sys\nprev = None\nWRAP_CONST = 4294967296\nfor line in sys.stdin:\n current = int(line.strip())\n if prev is not None:\n diff = current - prev\n if diff < 0:\n diff += WRAP_CONST\n print(f\'{diff / 1000000:.6f}\')\n prev = current'
AFAICT here’s nothing wrong with the awk command, therefore you’ve got non-printing junk at the end of the file. Yes, I get the same result if I put a ^Z at the end of the file.
If it’s not convenient to get a clean file, you could add /\032/ {next} to the beginning of the awk expression: