I have a script for daily monitoring of my system that works based on reading from a log file.
The command I enter to read and parse the string in the log file using the sed
is as follows:
lastline= `cat logs1/$file | sed '/.\{100\}/!d' | sed -n '$p'`
Although this command works well, it takes a long time to execute and I have to reduce the time complexity of its execution. So, Unable to reduce file size. Do you suggest a better solution or alternative to this command?
logfile has 2-3 million lines and its data is like this:
21/11/02 10:05:53.906 | OUT | OUT | [.0772230000340600720676E00000003406 100210055390 121676570608000000NOH1N1AFRN00AFRN136220211102100553254IRT1AFRN000100676 20211102000000029700000003581320000001463900070 1 1 120211102100553 H110B 0300000000 184 202111020000000041 184980011 1849800118480208316 0000000000000000001 184-IR98001 080210 20211102085506 LJA1TSEDRHAHUB220000001463900 0000000000000 0000000000000000000000000.]
21/11/02 10:05:55.607 | OUT | IN | [.000899.]
21/11/02 10:06:00.711 | OUT | IN | [.000899.]
21/11/02 10:06:05.714 | OUT | IN | [.000899.]
21/11/02 10:06:06.014 | OUT | OUT | [.0772230000340700720676E00000003407 100210060601 121676574028000000NOH1N1SARV00SARV136220211102100605261IRT1SARV000100676 20211102000000100400000000992620000007140000070 1 1 120211102100605 H110B 0300000000 120 202111020000002132 120980011 1209800112080208316 0000000000000000001 120-IR98001 20211102100448 LJA1TSEDRHFHUB220000007140000 0000000000000 0000000000000000000000000.]
In some lines (like line 3,4,2) we have incomplete data. So we should look for the last line with complete data. there is no set rule that I can use to determine the exact number of lines in which complete data exist. There may not be complete data up to line 1000 and it will not return the correct output. (this is why tail
does not work)
P.S. Part of the code can be seen in this link : here