Using a batch file...I want to search a text file for a specific word and if found I want to echo all the found lines to a new file "UNLESS" that line also has another specific word.
This is what I have tried so far, but it seems to write everything to outbound.txt and not loop through the error handling:setlocal enabledelayedexpansion
for /f "tokens=* skip=2 " %%b in (D:\Tivoli_Exclude\Filling_Temp.txt) do (
find /i "DIRINFO" \\D:\Tivoli_Exclude\Filling_Temp.txt > NUL
if %ERRORLEVEL% EQU 0 (
echo %%b >>D:\Tivoli_Exclude\Outbound.txt
) Else (
echo %%b >>D:\Tivoli_Exclude\Keep_Onsite.txt
)
)
Contents of input file(Filling_Temp.txt):---------- D:\TIVOLI_EXCLUDE\FULLSTATUS.TXT
000229 CTAPEBACK01 Filling
000528 CTBACK2 Filling
000539 DIRINFO_TA- Filling
000567 CTBACK4 Filling
000605 CTBACK1 Filling
000620 CTAPEBACK01 Filling
000622 CTAPEBACK01 Filling
000630 DIRINFO_TA- Filling
000652 CTBACK2 Filling
000663 CTBACK3 Filling
000670 CTAPEBACK01 Filling
000702 CTBACK2 Filling
000706 CTBACK3 Filling
000754 CTAPEBACK01 Filling
000799 CTBACK1 Filling
000913 CTBACK2 Filling
Standard %vars% don't update in loops, you could use this instead: if not errorlevel 1 (It won't work properly with negative errorlevels, but I'm pretty sure that fine only returns zero or greater.
... but if I understand correctly you want all lines that contain "DIRINFO" in one file and lines that don't in another. Th "/v" switch to find could be helpful:
<Untested>
>> D:\Tivoli_Exclude\Outbound.txt find /i "DIRINFO" < D:\Tivoli_Exclude\Filling_Temp.txt >> D:\Tivoli_Exclude\Keep_Onsite.txt find /v /i "DIRINFO" < D:\Tivoli_Exclude\Filling_Temp.txt
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |