Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7898627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:29:03+00:00 2026-06-03T08:29:03+00:00

I’m trying to create a batch that creates a fileC.txt containing all lines in

  • 0

I’m trying to create a batch that creates a fileC.txt containing all lines in fileA.txt except for those that contains the strings in the lines in fileB.txt:

Pseudo:

foreach(line L in fileA.txt)
     excluded = false
     foreach(string str in fileB.txt)
          if L contains str 
               exclude = true
     if !excluded
          add L to fileC.txt

if L !contains

For example

fileA.txt: (all)

this\here\is\a\line.wav
and\this\is\another.wav
i\am\a\chocolate.wav
peanut\butter\jelly\time.wav

fileB.txt: (those to be excluded)

another.wav
time.wav

fileC.txt: (wanted result)

this\here\is\a\line.wav
i\am\a\chocolate.wav

I’ve been fiddling around with FINDSTR but I just can’t seem to puzzle it together.. any help or pointers greatly appreciated!

Cheers!
/ Fredde

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:29:05+00:00Added an answer on June 3, 2026 at 8:29 am

    The answer should be this simple:

    findstr /lvg:"fileB.txt" "fileA.txt" >fileC.txt
    

    And with your example, the above does give the correct results.

    But there is a nasty FINDSTR bug that makes it unreliable when using multiple case sensitive literal search strings. See Why doesn't this FINDSTR example with multiple literal search strings find a match?, as well as the answer that goes with it. For a “complete” list of undocumented FINDSTR features and bugs, see What are the undocumented features and limitations of the Windows FINDSTR command?.

    So the simple code above can fail depending on the content of the files. If you can get away with using a case insensitive search, then the solution is simple.

    findstr /livg:"fileB.txt" "fileA.txt" >fileC.txt
    

    Edit: Both versions above will fail if fileB.txt contains \\ or \". In order to work properly, those strings must be escaped as \\\ and \\"

    But if you must use a case sensitive search, then there is no simple solution. Your best bet for a pure batch solution might be to use the /R regular expression option. But then you will have to create a modified version of fileB.txt where all regex meta-characters are escaped so that the strings give the correct literal search. That is a mini project in and of itself.

    Perhaps your best option for a case sensitive solution is to get a 3rd party tool like grep or sed for Windows.

    Edit: Here is a reasonably performing pure batch solution that is nearly bullet proof

    I looked into doing something like the proposed logic in your question. But using batch to read all lines in a file is relatively slow. This solution only reads the exclude file line by line. It uses FINDSTR to read the lines in “fileA.txt” repeatedly, once per search string. This is a much faster algorithm for a batch file.

    The traditional method to read a file is to use a FOR /F loop, but there is another technique using SET /P that is faster, and it is safe to use with delayed expansion. The only limitations to this method are:

    • It strips trailing control characters from the line
    • It is limited to 1021 bytes per line
    • Each line must be terminated by <CR><LF> as is the Windows standard. It will not work with unix style lines terminated by <LF>

    The search strings must have each \ and " escaped as \\ and \" when they are used with the /C option.

    @echo off
    setlocal enableDelayedExpansion
    copy fileA.txt fileC.txt >nul
    for /f %%N in ('find /c /v "" ^<fileB.txt') do set len=%%N
    <fileB.txt (
      for /l %%N in (1 1 !len!) do (
        set "ln="
        set /p "ln="
        if defined ln (
          set "ln=!ln:\=\\!"
          set ln=!ln:"=\"!
          move /y fileC.txt temp.txt >nul
          findstr /lv /c:"!ln!" temp.txt >fileC.txt
        )
      )
    )
    del temp.txt
    type fileC.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.