Search code examples
stringbatch-filetokendelimiterfindstr

Findstr /g with token or delim


Suppose we have 2 files

First.txt

123
456

And Second.txt

789;123
123;def
482;xaq

What i need is to find the lines in the second file only containing entries of the first file in first column (token 1, delim ; ). This is what i need:

Output.txt

123;def

Of course,

findstr /g:first.txt second.txt

will output both lines:

789;123
123;def

Any idea how i can mix findstr and for /f to get the needed output? Thank you!


Solution

  • If all of the elements in the first column are of the same length, then the simple answer would be

    findstr /b /g:first.txt second.txt
    

    Note however that if first.txt contains a line 12 then this would match 123;abc and 129;pqr in the second file.