I am trying to summarise a table of data that changes everyday. I have already summarised the table to only display rows with entries that are larger than 30.
However, on some days, there are no entries more than 30 in the original table. When that happens, i do not need the entire section that is empty in the summary. How do i then remove the entire header for those sections?
Ideally, if there are no entries in all 5 sections, there should not be any lines printed ( or just a string that says: "None: there is no entry larger than 30" as i was trying to do)
Example of a summarised table with 5 sections, summarised_output.txt:
=========================================================================================================
Month: Jun
Counter Name 06/04 18:00 06/04 17:00 06/04 16:00 06/04 15:00
=========================================================================================================
SYS.SYS.SYS.SYS.SYS.SYS. : 45 45 45 45
SYS.SYS.SYS.SYS.SYS.SYS. : 45 45 45 45
=========================================================================================================
Month: Jun
Counter Name 06/05 14:00 06/05 13:00 06/05 12:00 06/05 11:00
=========================================================================================================
SYS.SYS.SYS.SYS.SYS.SYS. : 45 45 45 45
SYS.SYS.SYS.SYS.SYS.SYS. : 45 45 45 45
=========================================================================================================
Month: Jun
Counter Name 06/05 10:00 06/05 09:00 06/05 08:00 06/05 07:00
=========================================================================================================
=========================================================================================================
Month: Jun
Counter Name 06/05 06:00 06/05 05:00 06/05 04:00 06/05 03:00
=========================================================================================================
SYS.SYS.SYS.SYS.SYS.SYS. : 45 45 45 45
SYS.SYS.SYS.SYS.SYS.SYS. : 45 45 45 45
=========================================================================================================
Month: Jun
Counter Name 06/04 18:00 06/04 17:00 06/04 16:00 06/04 15:00
=========================================================================================================
SYS.SYS.SYS.SYS.SYS.SYS. : 45 45 45 45
SYS.SYS.SYS.SYS.SYS.SYS. : 45 45 45 45
=========================================================================================================
As you can see, the third section is empty because there is no entry in the original_output.txt file higher than 30. But the header is still there.
My summary code( worked):
awk '$1=="Month:"||$1==""||$1=="Counter"||(index($1, "=")!=0)||$3>=30|| $4>=30 || $5>=30||$6>=30' original_output.txt>>summarised_output.txt
My attempt at deleting the header (doesn't work):
touch summarised_output_temp.txt
awk '{if ($1=="Month:"||$1==""||$1=="Counter"||(index($1, "=")!=0)||$3>=30|| $4>=30 || $5>=30||$6>=30) print $0}' original_output.txt >> summarised_output_temp.txt
if (((wc -l < summarised_output_temp.txt)==42))
then
echo "None: there is no entry larger than 30" >> summarised_output.txt
else
cat output_7_temp.txt>>summarised_output.txt
fi
The error received for the attempt:
line 3: ((: (wc -l output_7_temp.txt | awk {print $1})==42: syntax error: invalid arithmetic operator (error token is ".txt | awk {print $1})==42")