简体   繁体   中英

Is there powershell command to select the line with particular string(time) and have to print count values Total calls Generated:156?

  • step-1 we have to go the location path -eg -C:\\Jobs\\logs.

  • step-2 open the log file with current date in format-'YYYY-MM-DD'(eg-2021-06-16.log).

  • step-3 for completion time which will be input. In this scenario-5:02:21. I have to print the count values for the below sample log text.

    2021-06-16 03:30:00.7185 INFO Running GetCallGenForFullRun query
    2021-06-16 03:32:49.1254 INFO Query complete. Elapsed time: 168 seconds, Call Candidiate count: 713755
    2021-06-16 03:32:49.1254 INFO Generating Call Logs...
    2021-06-16 05:02:11.6588 INFO Deleting records from PRESCRIPTION_CallGen table
    2021-06-16 05:02:21.2377 INFO Call Gen Program Complete. Total elapsed time: 0 seconds, Total Calls Generated: 156

I need powershell command to select the line with time-5:02:21 and have to print Total calls Generated:156.

i tried the below code

cd C:\Jobs\logs
$TodayDate = $(Get-Date -f yyyy-MM-dd)
$Text = Select-String -Path "C:\Jobs\CallGenJob\logs\$TodayDate.log" -Pattern '2021-06-16 05:02:21'
echo $Text

get-content -path C:\\your\\path.txt | findstr "$text"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM