0

I have two text files mount.txt and mount2.txt and I've been trying to separate new lines (lines that were not in mount.txt but are in mount2.txt) from old lines (lines that were in mount.txt but are not in mount2.txt). I know this must be possible with something like:

fc mount.txt mount2.txt >out.txt
for /F "tokens=*" %%A in  (out.txt) do (
 ::separate Line)

The output of the fc command looks like this:

Comparing files mount.txt and MOUNT2.txt
***** mount
ITCMDLogo
CBS
***** MOUNT2
Logo
ITCMDSecondLogo
CBS
*****

***** mount
MozillaPlugins
Acknowledgements
ReadMe\Palemoon-Portable-license.txt
***** MOUNT2
MozillaPlugins
ReadMe\Palemoon-Portable-license.txt
*****

I'm in quite a pickle on how exactly to go about doing this, as I'm still very much a beginner on for /f loops and setlocals.

barlop
  • 23,380
  • 43
  • 145
  • 225
Mark Deven
  • 1,488
  • 9
  • 40
  • 71
  • 1
    i've assumed your title was mistitled and you meant 'in' rather than 'is', is that right? if not please correct your title, because it didn't make sense. – barlop Jun 15 '18 at 13:59
  • I don't know fc that much, and, I know this might be a bit unnecessary but it might make it a bit clearer. Can you include the content of each file? (I know your fc output might indicate the contents of each file, but it'd be clearer if you included the contents of each file before the fc command) – barlop Jun 15 '18 at 14:01
  • Instead of fc use `findstr /V /I /B /E /G:mount.txt – LotPings Jun 15 '18 at 14:57
  • Well, I tried it with this file here, and tried just removing a line or two, and adding some random ones: https://1drv.ms/t/s!AlRLV33Rdz2CgrgbGh5l2u5E4o6uYw (note that the output will be different than my example, which I simplified. The output for this file will have paths). – Mark Deven Jun 15 '18 at 16:02

1 Answers1

0

Instead of fc use findstr with the options:

 /V         Prints only lines that do not contain a match.
 /I         Specifies that the search is not to be case-sensitive.
 /B         Matches pattern if at the beginning of a line.
 /E         Matches pattern if at the end of a line.
 /G:file    Gets search strings from the specified file(/ stands for console).

You can gather the options with only one /

> findstr /VIBELG:mount.txt <mount2.txt
Logo
ITCMDSecondLogo
LotPings
  • 7,011
  • 1
  • 15
  • 29
  • That gave me a bunch of lines, probably around 200, in response, when I know there are only 4 differences. – Mark Deven Jun 15 '18 at 15:58
  • That shouldn't happen, difficult to guess/tell a reason without knowing the file content or encoding. There are [restrictions with findstr](https://stackoverflow.com/questions/8844868/what-are-the-undocumented-features-and-limitations-of-the-windows-findstr-comman) but I never met them with plain ascii files. Maybe a gui program like [WinMerge](http://winmerge.org) is an option for you? – LotPings Jun 15 '18 at 16:09
  • I have backslashes in my files, those effect findstr dont they – Mark Deven Jun 15 '18 at 16:35
  • I've tried a bunch of ways like findstr and even for loops with echo, but fc is the only way that's remotely fast for 2,000 line files and I know the for loop is possible. – Mark Deven Jun 15 '18 at 16:36
  • Then please add an /L to the switches to shut off the default /R – LotPings Jun 15 '18 at 16:49
  • That still shows a bunch of lines with `findstr /L /I /B /E /V /G:mount.txt – Mark Deven Jun 15 '18 at 17:27
  • does the /l support colons and backslashes and dollar signs? – Mark Deven Jun 18 '18 at 00:40
  • The /L switch will find/compare strings literally chars have no more a special RegEx meaning. See `findstr /?` or http://ss64.com/findstr.html – LotPings Jun 18 '18 at 04:13