find substring and delete but keep the rest

September 28, 2010 at 14:39:21
Specs: Windows XP
I need help write code to just delete the substring and still keep/print the rest of the line.

The code below only print those line that doesn't match. I need it to delete the subtring and print what ever left from the line that have matched string also.

Example:


CleanUp.txt file contain:

mymail=Mail Enabled Service Accounts,mymail=Users,mymail=Users,
mymail=Testers,mymail=Associates,mymail=Users,mymail=Users,

unfilter.txt file contains:

mycomputer mymail=Mail Enabled Service Accounts,mymail=Users,mymail=Users, mylabtop
changetype: add
objectClass: top

I want the aswer to be:

mycomputer mylabtop
changetype: add
objectClass: top

thanks


@echo off
if exist unfiltered.txt(
rename unfiltered.txt unfiltered.tmp
)
findstr /v /g:CleanUp.txt unfiltered.tmp >> unfiltered.txt
if exist unfiltered.tmp(
del unfiltered.tmp
)


See More: find substring and delete but keep the rest

Report •

#1
September 28, 2010 at 18:39:10
download gawk for windows then do this


C:\test>gawk "FNR==NR{a[$0]}NR>FNR{for(i in a){ sub(i,\"\")};print}" cleanup unfilter
mycomputer  mylabtop
changetype: add
objectClass: top

GNU win32 packages | Gawk


Report •
Related Solutions


Ask Question