user3437212
user3437212

Reputation: 675

String Comparision across files

I have two files

file1 looks like this

M:\admin_view\GemCommonApplications\AnalysisAndDesign\prototype
M:\admin_view\GemCommonApplications\AnalysisAndDesign\GeminiCommonTables.xls
M:\admin_view\GemCommonApplications\AnalysisAndDesign\EntryCapDBObjectDetails.xls
M:\admin_view\GemCommonApplications\AnalysisAndDesign\Security
M:\admin_view\GemCommonApplications\AnalysisAndDesign\ViewDataSpecification
M:\admin_view\GemCommonApplications\AnalysisAndDesign\Security\SUCS
M:\admin_view\GemCommonApplications\Deployment\ApplicationXML
M:\admin_view\GemCommonApplications\Deployment\BuildScripts
M:\admin_view\GemCommonApplications\Deployment\Build

file2 looks like this

M:\admin_view\GemCommonApplications\AnalysisAndDesign\prototype\Common
M:\admin_view\GemCommonApplications\AnalysisAndDesign\prototype\images
M:\admin_view\GemCommonApplications\AnalysisAndDesign\prototype\Main
M:\admin_view\GemCommonApplications\AnalysisAndDesign\prototype\stylesheet
M:\admin_view\GemCommonApplications\AnalysisAndDesign\prototype\WalkThru
M:\admin_view\GemCommonApplications\Deployment\ApplicationXML\Batch\etc

Now I want to check if each line in file1 is a subtring in file2 lines. I want to get an output which would be like all the lines in file1 which are not a substring in any of the lines in file2.

example:

M:\admin_view\GemCommonApplications\AnalysisAndDesign\prototype

should not be in the output as it is a substring of lines 1-5

M:\admin_view\GemCommonApplications\Deployment\BuildScripts

should be in the output as its not a substring in file2.

I tried findstr /v but the output seemed weird. Can someone please help?

Upvotes: 0

Views: 22

Answers (1)

MC ND
MC ND

Reputation: 70923

I don't know a way to use findstr to search strings and output the search term instead of the matching/not matching lines.

The only way i see is to test each line in file1 against file2 and if it is not found then echo the line

@echo off
  for /f "delims=" %%a in (file1) do (
      findstr /l /b /i /m /c:"%%a" file2 >nul || echo %%a
  )

For each line in file1, search it in file 2 and if not found echo the line readed from file1

Upvotes: 1

Related Questions