Appending the filename to the beginning of each line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RayStaton
Posts: 1
Joined: 10 Apr 2014 13:11

Appending the filename to the beginning of each line

#1 Post by RayStaton » 10 Apr 2014 13:23

Hi,

I have a batch file which searches through a text file for keywords for errors. It uses FINDSTR to do this and then it outputs the problem lines to another text file...


Here's the bat file..

findstr /i /n /g:"c:\Users\statrox\WINLC\KEYS_IN1.TXT" "%~DPN1.LOG" >> "C:\Users\statrox\WINLC\%~n1.tmp"

findstr /i /r /v /g:"c:\Users\statrox\WINLC\KEYS_OUT1.TXT" "C:\Users\statrox\WINLC\%~n1.tmp"

del "C:\Users\statrox\WINLC\%~n1.*"


Here's an example of the output.... for the lines beginning with xxxx: I need the name of the file appended in front of each line.. so the lines should look like the following....

F:\2011-001\STATIS~1\Pubs\WM_201~1\Work\VALIDA~1\Programs\vtdemog4.LOG:1114:WARNING 1-322: Assuming the symbol TRANSPOSE was misspelled as transpoze.

instead of looking like this...

1114:WARNING 1-322: Assuming the symbol TRANSPOSE was misspelled as transpoze.
1407:WARNING 1-322: Assuming the symbol TRANSPOSE was misspelled as transpoze.
1700:WARNING 1-322: Assuming the symbol TRANSPOSE was misspelled as transpoze.
1993:WARNING 1-322: Assuming the symbol TRANSPOSE was misspelled as transpoze.
2284:WARNING 1-322: Assuming the symbol TRANSPOSE was misspelled as transpoze.
2579:WARNING 1-322: Assuming the symbol TRANSPOSE was misspelled as transpoze.

F:\2011-001\STATIS~1\Pubs\WM_201~1\Work\VALIDA~1\Programs>del "C:\Users\statrox\WINLC\vtdemog4.*"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Appending the filename to the beginning of each line

#2 Post by foxidrive » 10 Apr 2014 13:40

The easy way is to add /s to your findstr command, if that is enough for you.

Post Reply