As only show the words found in the findstr

324 views Asked by At

How do I display only the words found in the search instead of displaying the lines?

My code:

Findstr /li /G:"List.txt" "File.txt">"Result.TxT"

List:

Disc
Music
Song
Album

Result:

DISC1312we7das67da
13dsdsa67dsahdsa7aMUSIC
dsadsdfdsaSONG1223234235

The desired result:

Disc
Music
Song
1

There are 1 answers

0
Aacini On BEST ANSWER
@echo off

(for /F %%a in (List.txt) do (
   Findstr /li /C:"%%a" "File.txt" > NUL
   if not errorlevel 1 echo %%a
)) > "Result.TxT"