3

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
Paul
  • 2,620
  • 2
  • 17
  • 27
user0404
  • 113
  • 3
  • 14
  • 1
    yeah,while using FINDSTR i can print only matching line but i also need line which comes before matching string. – user0404 Jul 10 '13 at 13:02

2 Answers2

5

try this with grep for Windows:

grep -1 "ActualStartDate:" *.txt

output is eg.:

file.txt-cds
file.txt:ActualStartDate: invalid date
Endoro
  • 37,015
  • 8
  • 50
  • 63
3

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

foxidrive
  • 40,353
  • 10
  • 53
  • 68