I've wrote a batch script that to capture a specific location string from a text file, for example:
The text file contains:
Copyright Version 5.39
Network activity progressing...
Thread Time(s) Throughput(KB/s) Avg B / Compl
====== ======= ================ =============
0 600.088 73245.829 45502.632
1 594.574 84312.667 44974.835
2 594.569 62862.184 44547.486
3 599.665 66407.148 45056.270
4 600.633 61846.742 44741.495
5 594.569 45967.918 46745.891
6 594.937 72678.901 45115.861
7 593.981 86081.374 45148.288
8 593.975 35448.661 44118.093
9 602.451 64144.439 44708.118
10 599.760 26404.342 53411.916
11 594.569 64959.044 44525.327
12 594.564 63125.969 44512.966
13 602.999 71045.335 45266.114
14 599.719 19782.849 54192.569
15 594.574 61670.399 44341.198
16 599.681 71804.247 44954.492
17 593.980 21731.533 43903.776
18 593.979 22436.796 43919.327
19 599.748 21296.983 53880.446
##### Totals: #####
Bytes(MEG) realtime(s) Avg Frame Size Throughput(MB/s)
================ =========== ============== ================
639903.106318 600.002 4289.297 1066.502
Throughput(Buffers/s) Cycles/Byte Buffers
===================== =========== =============
17064.032 41.043 10238449.701
DPCs(count/s) Pkts(num/DPC) Intr(count/s) Pkts(num/intr)
============= ============= =============== ==============
3081479.450 0.085 2302796.649 0.113
Packets Sent Packets Received Retransmits Errors Avg. CPU %
============ ================ =========== ====== ==========
66199455 156432871 4 0 99.998
There are total 58 lines in the text file, and I will need to get Throughput(MB/s) value, which allocated in line 43, and the 4th string, from above example it is 1066.502.
So, I created a batch script to filter out the number:
set "lom1="
for /f "skip=48 delims=" %%i in LOM_1.log) do if not defined lom1 set "lom1=%%i"
echo !lom1! >> temp1.txt
for /f "tokens=4" %%j in temp1.txt do echo %%j >> result.log
But, now the source text got errors and it increases random lines, for example:
Copyright Version 5.39
Network activity progressing...
ERROR: WaitForWorkerThreads failed: WaitForMultipleObjects returned an unexpected value
ERROR: DoWork failed: WaitForWorkerThreads(threads_finished) timed out
ERROR: StartSenderReceiver in thread: 9 failed: closesocket, GetLastError: 10093 - Either the application has not called WSAStartup, or WSAStartup failed.
ERROR: StartSenderReceiver in thread: 13 failed: closesocket, GetLastError: 10093 - Either the application has not called WSAStartup, or WSAStartup failed.
ERROR: StartSenderReceiver in thread: 16 failed: closesocket, GetLastError: 10093 - Either the application has not called WSAStartup, or WSAStartup failed.
Thread Time(s) Throughput(KB/s) Avg B / Compl
====== ======= ================ =============
0 600.088 73245.829 45502.632
1 594.574 84312.667 44974.835
2 594.569 62862.184 44547.486
3 599.665 66407.148 45056.270
4 600.633 61846.742 44741.495
5 594.569 45967.918 46745.891
6 594.937 72678.901 45115.861
7 593.981 86081.374 45148.288
8 593.975 35448.661 44118.093
9 602.451 64144.439 44708.118
10 599.760 26404.342 53411.916
11 594.569 64959.044 44525.327
12 594.564 63125.969 44512.966
13 602.999 71045.335 45266.114
14 599.719 19782.849 54192.569
15 594.574 61670.399 44341.198
16 599.681 71804.247 44954.492
17 593.980 21731.533 43903.776
18 593.979 22436.796 43919.327
19 599.748 21296.983 53880.446
##### Totals: #####
Bytes(MEG) realtime(s) Avg Frame Size Throughput(MB/s)
================ =========== ============== ================
639903.106318 600.002 4289.297 1066.502
Throughput(Buffers/s) Cycles/Byte Buffers
===================== =========== =============
17064.032 41.043 10238449.701
DPCs(count/s) Pkts(num/DPC) Intr(count/s) Pkts(num/intr)
============= ============= =============== ==============
3081479.450 0.085 2302796.649 0.113
Packets Sent Packets Received Retransmits Errors Avg. CPU %
============ ================ =========== ====== ==========
66199455 156432871 4 0 99.998
You can see that there are additional ERROR lines in the text file, that means I cannot still use the for /f "skip=48" command to filter the right line out, so, I'd like to know, if any batch command or for /f parameters can be used to count up from last line so that it will be always fix line number, for example on above text content, if I count up from last line and the 16th line is what I want, then I can keep to export the 16th line (count from the last line), then to capture the 4th string for the number.
I tried to google but cannot find useful information.
Here it is a different and simpler approach. Instead of get the line two lines below
Throughput(MB/s), we can get the line three lines aboveThroughput(Buffers/s)that can be get via a singlefindstrcommand.If you want to process several *.log files, just insert the
findstr ... | for ...commands into a cycle that process the files.EDIT 2024/03/21: Get Errors number
I was reading your request in the comments below phuclv's answer about get the "Errors" number. Get such a number is very simple in the Batch file:
If the
Packets Sent Packets Received Retransmits Errors Avg. CPU %is the last section in the file, just do this:and that is it!
;)