![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-22 14:38 |
47,812 topics / 349,917 posts / today 0 new / 48,272 members |
| DOS批处理 & 脚本技术(批处理室) » Please tell me how to display the line before the line found by findstr. |
| Printable Version 2,689 / 0 |
| Floor1 wiq | Posted 2017-03-02 16:22 |
| 初级用户 Posts 35 Credits 179 | |
|
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 ] |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |