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 #]
Inside the script will look like this.
window.x=[some #]
window.y=[some #]
window.width=[some #]
window.height=[some #]
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
findstr /v /r /c:"window.width=\[[0-9]*\
to eliminate that line for example.
~bp
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=*" )
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\>\<wi dth\>\<hei ght\>=\[[0 -9]*\]" in.txt
findstr /v /r /c:"window.[\<x\>\<y\>\<wi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the update, Bill.
I've found separating the word boundaries with spaces and removing the /C literal switch works:
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]*\]"
@NewVillageIT,
That last one is a bit too aggressive, notice the following test case where it discards too many lines:
IN.TXT
OUT.TXT
~bp
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
OUT.TXT
FIRST
LAST
~bp
Thanks, glad that was useful.
~bp
~bp
There will be nothing else on the line?
~bp