Link to home
Start Free TrialLog in
Avatar of GGHC
GGHC

asked on

Windows Script to search a files and delete value

Looking for a script that will search/delete a line in an ini file. The script should only delete the line that matches, nothing else.

Inside the script will look like this.

window.x=[some #]
window.y=[some #]
window.width=[some #]
window.height=[some #]
Avatar of Bill Prew
Bill Prew

Which line do you want to delete?

There will be nothing else on the line?

~bp
At a command line (or in a BAT file) you could just do:

findstr /v /r /c:"window.width=\[[0-9]*\]" in.txt > out.txt

to eliminate that line for example.

~bp
Avatar of GGHC

ASKER

This worked nicely!
I used findstr /v /r /c:"window.height=*"
How can I add the other search criteria into the same findstr line? ( "window.width=*" , "window.x=*", "window.y=*" )
This seems to work. I don't see why I have to add the outside "[" without the closing "]". Maybe Bill or another expert can explain why. Anyway, it works.

findstr /v /r /c:"window.[\<x\>\<y\>\<width\>\<height\>=\[[0-9]*\]" in.txt
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the update, Bill.

I've found separating the word boundaries with spaces and removing the /C literal switch works:
findstr /v /r "window.\<x\> \<y\> \<width\> \<height\> =\[[0-9]*\]"

Open in new window

@NewVillageIT,

That last one is a bit too aggressive, notice the following test case where it discards too many lines:

IN.TXT
FIRST
window.x=[1234]
window.y=[1235]
window.z=[1235]
window.width=[1236]
window.height=[1237]
door.x=[1234]
door.y=[1235]
LAST

Open in new window


OUT.TXT
FIRST
LAST

Open in new window


~bp
Thanks, glad that was useful.

~bp