1

I have around 200 directories. Each directory contains only one log file.
first line of log file specifies the time the particular job start and last line the job end time.

I can export the directory names to a CSV file. I need help with capturing start and end time from the log file inside of each directory.

please share command/loop. Here is an example.

Direcotry PS-PR-9928883838383 
log name PS-PR-9928883838383.log

within the log, there will timestamp of when it started and the last timestamp.

  2019-08-29::22:59:13 INFO com.bns.csm.####.####AppHandlerImpl:868 [pool-1-thread-5] #### = /bns/csm/ac_data/workdir/MsgService/####/Apps/####/working/PS-PR-20190829225849147/priceReq_@@@@_PS-PR-20190829225849147_20190830.csv completion confirmation is known by below line 2019-08-29::22:59:22 INFO com.bns.csm.####24 [pool-87-thread-1] THREAD for ### extract with output location = /bns/csm/ac_data/workdir/MsgService/####/Apps/@@@@/working/PS-PR-20190829225849147/priceResponse_@@@@_PS-PR-20190829225849147_20190830.txt: End. –
  • 1
    can u share those two lines of a file? – msp9011 Aug 30 at 4:32
  • 1
    2019-08-29::22:59:13 INFO com.bns.csm.####.####AppHandlerImpl:868 [pool-1-thread-5] #### = /bns/csm/ac_data/workdir/MsgService/####/Apps/####/working/PS-PR-20190829225849147/priceReq_@@@@_PS-PR-20190829225849147_20190830.csv completion confirmation is known by below line 2019-08-29::22:59:22 INFO com.bns.csm.####24 [pool-87-thread-1] THREAD for ### extract with output location = /bns/csm/ac_data/workdir/MsgService/####/Apps/@@@@/working/PS-PR-20190829225849147/priceResponse_@@@@_PS-PR-20190829225849147_20190830.txt: End. – Loke12k Aug 30 at 4:50
  • 1
    to add, the directory name is also created with etension of YYYYMMDDHHMMSS; so that would be the start time. ENd time would have to be fetched from log file. – Loke12k Aug 30 at 4:59
  • 1
    please add your sample log file data to your Question. It's no use in a comment. – cas Aug 30 at 6:16
  • 1
    that can't be the actual data because it's only one line, not the two that were mentioned. it looks like you've just copy-pasted the comment. please copy and paste directly from your terminal, and format it as code. it's important to have the actual data in the same format as on your machine because details like linefeeds and spaces matter. – cas Aug 30 at 6:43
1

Try something like this:

find . -type f -name 'PS-PR-*.log' -exec awk '
  NR==1 { printf "%s,%s,", FILENAME, $1};
  $NF == "End." {print $1}' {} +

You haven't posted your log data yet, so i'm unsure if the that appears to be on the end of the End. line is actually there or if it is some copy and paste artifact. The above assumes it isn't there.

If it is really there, then the End. is in the 2nd last field, not the last. So use:

$(NF-1) == "End." {print $1}

instead.

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.