The line before does not include the character to be found. How to display the line before the line found by findstr?
set ACCOUNT=1234
set DATE=20170302
set DIR=d:\log\
for %%i in (%DATE%) do findstr /nisd:%DIR% "%ACCOUNT%" %%i.log >>log.txt
The line in the log that includes the account number has no time, and the previous line has time, but the previous line does not have the account number. We cannot display all the lines with time because there are logs of other accounts.
Under Linux, awk can be used to achieve: awk '/1234/{print a"\n"$1;}{a=$0}' 20170302.log
[ Last edited by wiq on 2017-3-3 at 09:20 ]
set ACCOUNT=1234
set DATE=20170302
set DIR=d:\log\
for %%i in (%DATE%) do findstr /nisd:%DIR% "%ACCOUNT%" %%i.log >>log.txt
The line in the log that includes the account number has no time, and the previous line has time, but the previous line does not have the account number. We cannot display all the lines with time because there are logs of other accounts.
Under Linux, awk can be used to achieve: awk '/1234/{print a"\n"$1;}{a=$0}' 20170302.log
[ Last edited by wiq on 2017-3-3 at 09:20 ]

