Page 1 of 1

Refining Search Criteria

Posted: Tue May 22, 2012 4:29 pm
by TextPad_Newbie
I am trying to remove some lines from group of text files using Find and Replace. I have approx. 6,000 of these files. The lines I am trying to remove are:

REM net use lpt1: \\abcprint\abfde012p
REM net use lpt2: \\efgprint\kub068p
REM net use lpt3: \\hklprint\abc????p

In the Search > Find in Files window I search for net use lpt This returns all the files with the entries I am looking to remove. I then select and open the files and then use the Search > Replace window, I enter .*[lpt]*p$ in the Find What field and leave the replace field blank so that it will remove the line.

My issue is that it is removing other lines that I do not want it to. For example it is removing:

rem net use y: \\abc\app
:: Check if on XenApp
cscript y:\update\printeradd.vbs /d \\abc\xyz025p

Here is an example of the text file:

@echo off
::::net time \\atl /set /y > nul
rem net use y: \\abc\app
Net Use U: \\ADCFS1\Users\test
:: Check if on XenApp
cscript y:\update\printeradd.vbs /d \\abc\xyz025p
cscript y:\update\printeradd.vbs \\abc\xyz027c
cscript y:\update\printeradd.vbs \\abc\xyz026m
REM net use lpt1: \\abcprint\abfde012p
REM net use lpt2: \\efgprint\kub068p
REM net use lpt3: \\hklprint\abc????p
C:\windows\lmscript.$$$
@echo on

I am sure that this is childsplay but my inner child has run away. What do I need to use in the Find What field to only select the lines containing the rem net use lpt variable? Any help would be greatly appreciated.

Posted: Tue May 22, 2012 8:26 pm
by MudGuard
the lines you want to delete contain the characters lpt in exactly this order.
What you are looking for are lines that
start with whatever
have any number of one of the letters l or p or t
end with a p.

.*lpt.*p$
is probably the expression you want to use

This searches for:
start with whatever
the letters l and p and t in exactly this order
whatever
end with p

Posted: Tue May 22, 2012 9:39 pm
by ben_josephs
And if you want to remove the entire line, including its line terminator, use
.*lpt.*p\n

It worked

Posted: Wed May 23, 2012 12:40 pm
by TextPad_Newbie
ben_josephs wrote:And if you want to remove the entire line, including its line terminator, use
.*lpt.*p\n
Thanks it worked. This gets me on the right track.