1

please i need your help on this topic.

i have 3 temp files and nbf.txt.
i want to copy each hour lines from this 3 temp files to nbf.txt:
inside each temp file we have
temp file for each hour:
tmp1
Receiveid Transaction
======================
2020-05-29 00->12

tmp2
Failed Transaction
===================
2020-05-29 00->1 failed

temp3
Failed Open Sessions Per Hour
==============================
2020-02-29 00->2 sessions

so i need to use sed for each temp file:

i am using the below command in my script:

sed -i -e '1,$p' nbf.txt -e '1,3d' tmp1
sed -i -e '1,$p' nbf.txt -e '1,3d' tmp2
sed -i -e '1,$p' nbf.txt -e '1,3d' tmp3

the result inside nbf.txt NB: please i need the below result using sed or tail or awk

Received Transactions Per Hour
==============================
2020-02-29 00->69646 requests

2020-02-29 23->82666 requests

2361523 Received Transactions


Rejected Transactions Per Hour
===============================

0 Rejected Transactions


Failed Open Sessions Per Hour
==============================
2020-02-29 00->2 sessions
2020-02-29 22->1 sessions

8 Failed Sessions

but not working corrdctly

2
  • Could you add a couple of lines from one of the logs, as an example? – Gerard H. Pille May 28 '20 at 16:21
  • I don't get where the failed and rejected connections come from. – Hauke Laging May 28 '20 at 17:17
1

In general there is no reason to pipe from cat to grep to awk and even to another awk because a single awk can do all that very well.

$ awk -F'[ :]' '/:/ { datestring=$1; a[$2]++;}; END { for(i=0;i<24;i++) '\
'{ ind=sprintf("%02d",i); '\
'printf "%s %2s->%7d\n",datestring,ind,(a[ind]>0) ? a[ind] : 0 ; }; }' \
Received_transaction.log-$Hour
2020-05-28 00->      0
2020-05-28 01->      0
2020-05-28 02->      0
2020-05-28 03->      0
2020-05-28 04->      0
2020-05-28 05->      0
2020-05-28 06->      0
2020-05-28 07->      0
2020-05-28 08->      0
2020-05-28 09->      0
2020-05-28 10->      0
2020-05-28 11->      0
2020-05-28 12->     13
2020-05-28 13->      0
2020-05-28 14->      0
2020-05-28 15->      0
2020-05-28 16->      0
2020-05-28 17->      0
2020-05-28 18->      0
2020-05-28 19->      0
2020-05-28 20->      0
2020-05-28 21->      0
2020-05-28 22->      0
2020-05-28 23->      0
1
  • 00:00 ====> 12:59 is 13 hours, not one. Due to race conditions there may be wrong entries in a file. Shall they be detected and ignored? Basically you are just counting the lines which contain a :, right? – Hauke Laging May 28 '20 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.