Example, I have a text file and the contents are: Dog Cat Horse 3456
Horse Dog Mouse 1234
Bird Cat Dog 4567
Dog Mouse Bird 1112
Horse Cow Fly 22234
Cow Dog Mouse 54444
Cow Fly Mouse 2323222How do I write a batch file that will remove any line that has "Dog Mouse" and "Cow Fly" but it has to be exact match so I don't want it to remove a line that might have "Dog" in it somewhere or "Cow" in it somewhere, etc.
I was able to use the Find command to delete specific single words but not the exact match of two words or more as they are placed in the sentence (e.g. "Dog Mouse")
Hope that makes sense.
Thanks!!!
If you want to match the strings of two words wherever they are placed in the line (i.e. "Dog Mouse Bird 1112" or "Cow Dog Mouse 54444") assuming the words are separated by just one space the following does the job
type file.txt | find /V "Dog Mouse" | find /V "Cow Fly" > file.new
Otherwise post again explaining better your needs.
I beleive that does it!!! I could've swore I tried something similar to it but oh well. Thank you so much!
Actually, one more thing... :) Is there a way to ignore duplicate lines and just keep one line of the lines so:
Dog Cat Horse 3456
Horse Dog Mouse 1234
Bird Cat Dog 4567
Dog Mouse Bird 1112
Dog Mouse Bird 1112
Dog Mouse Bird 1112
Horse Cow Fly 22234
Cow Dog Mouse 54444
Cow Fly Mouse 2323222
Cow Fly Mouse 2323222
Cow Fly Mouse 2323222I want to filter any duplicates and have the following result:
Dog Cat Horse 3456
Horse Dog Mouse 1234
Bird Cat Dog 4567
Dog Mouse Bird 1112
Horse Cow Fly 22234
Cow Dog Mouse 54444
Cow Fly Mouse 2323222Thanks again!!!
If the duplicate lines are grouped in bursts the following applies...
@echo off & setlocal EnableDelayedExpansion set /P row=< file.txt echo.%row%> file.new for /F "skip=1 delims=" %%j in (file.txt) do ( if not "%%j"=="!row!" echo.%%j>> file.new set row=%%j )
Otherwise the source file must be previously sorted, but the native order is lost.
Hmm.. it wont seem to work for me. Could you provide small amount of original and output text so I can see how the results worked out? Or can you maybe use my provided example text with this somehow?
Sorry, the script was untested and an extra space caused the bug. Please replace set row=%%j
with
(set row=%%j)
and the batch should work fine.
Excellent! Thanks a lot!!
I was trying this, but the SORT command does not seem to allow duplicate lines to be removed. find /V "Dog Mouse" file.txt | find /V "Cow Fly" | sort > file.new
Anyway, be aware of the SORT command, it may help you
