I have a log file which contains lot of logs and first column contains the epoch time stamp, Ideally they should be in sequence/sorted. however if something goes wrong in system timestamp resets to some default value and sequence breaks and restarts. I am trying to find the lines where sequence/sorting is getting borken. Please notice the sequence number in column one.
For example:
101 aaa bbb ccc
102 aa dd ff gg
103 asd asd asdas
104 something goes wrong
101 restarting the time stamp
103 new start
104 going fine
105 smae here
102 ahh something unexpected
Desired output:
104 something goes wrong
101 restarting the time stamp
105 smae here
102 ahh something unexpected
sort -c
helps, but I cannot store its output to any file for further processing. Please let me know if any alternate way is possible.
With awk:
There's not much to explain here, as you can see:
prev
is initially empty and considered equal to zero, which should be fine for Epoch time stamps unless you have log entries from before 1970. If you do, replace$1 < prev
withNR > 1 && $1 < prev
, since the first line cannot be out of order.