Solved Getting rid of certain lines in a textfile?

April 15, 2014 at 19:26:03
Specs: Windows 7
Hello, I hope this isnt too confusing to understand.

The file v.txt has 100s of filename destinations.

The file z.txt has 3 specific filename destinations that I want to remove from v.txt

Contents of z.txt:

c:\win\pcs\b
c:\win\p\cd
c:\windows\xp\dt

Here are 2 methods I tried that failed:

Method one:
setlocal ENABLEDELAYEDEXPANSION
set vidx=0
for /F "tokens=*" %%A in (z.txt) do (
SET /A vidx=!vidx! + 1
set jaret!vidx!=%%A
)
set jaret

SetLocal EnableDelayedExpansion
For /F "tokens=* delims=" %%A in (v.txt) Do (
Set TxtLine=%%A
Set TxtLine=!TxtLine:%jaret1%=!
Set TxtLine=!TxtLine:%jaret2%=!
Set TxtLine=!TxtLine:%jaret3%=!
echo !TxtLine!>tmp.4)
rename tmp.4 output.txt

Method 2:

setlocal ENABLEDELAYEDEXPANSION
set vidx=0
for /F "tokens=*" %%A in (z.txt) do (
SET /A vidx=!vidx! + 1
set jaret!vidx!=%%A
)
set jaret

findstr /x /v "%jaret1%" v.txt >> output.txt
findstr /x /v %jaret2% v.txt >> output.txt
findstr /x /v %jaret3% v.txt >> output.txt

Both methods are only removing the first variable "c:\win\pcs\b" and not removing the 2nd and 3rd variables from v.txt and outputting to output.txt . Any idea why? Thanks.


See More: Getting rid of certain lines in a textfile?

Report •


#1
April 16, 2014 at 01:48:59
@echo off
for /F "delims=" %%i in (z.txt) do type v.txt | find /V /I "%%i" >> output.txt

WARNING! Incorrect code, posted by error. The correct one will follow as soon as possible.

message edited by IVO


Report •

#2
April 16, 2014 at 02:29:15
✔ Best Answer
@echo off & setlocal EnableDelayedExpansion
copy v.txt $1.txt > nul
for /L %%i in (1 1 3) do (
  set /A n= %%i + 1
  for /F "delims=" %%j in (z.txt) do type $%%i.txt | find /V /I "%%j" > $!n!.txt
)
ren $!n!.txt output.txt
del $?.txt


Report •

#3
April 17, 2014 at 09:29:30
Thanks! It worked perfectly.

Report •

Related Solutions


Ask Question