Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return previous line with Findstr

I am running FINDSTR command to find specific text in .txt files. I want to print matching lines as well as 1 previous line.

findstr "ActualStartDate:"  * > a.txt

if my file is like this

abcd  
defg  
cds  
ActualStartDate: invalid date  

Result should be like this

cds  
ActualStartDate: invalid date
like image 848
user0404 Avatar asked Jan 18 '26 10:01

user0404


2 Answers

try this with grep for Windows:

grep -1 "ActualStartDate:" *.txt

output is eg.:

file.txt-cds
file.txt:ActualStartDate: invalid date
like image 126
Endoro Avatar answered Jan 21 '26 01:01

Endoro


There is a tool written as a batch file that can do this easily, which uses built in Windows scripting.

findrepl.bat - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697

like image 38
foxidrive Avatar answered Jan 21 '26 01:01

foxidrive