Solved

Windows Script to search a files and delete value

Posted on 2015-02-18
8
88 Views
Last Modified: 2015-02-25
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 #]
0
Comment
Question by:GGHC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 40617206
Which line do you want to delete?

There will be nothing else on the line?

~bp
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 40617225
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
0
 

Author Comment

by:GGHC
ID: 40617286
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=*" )
0
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 
LVL 24

Expert Comment

by:NVIT
ID: 40617442
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
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 40617526
The regular expression capability in FINDSTR is fairing simplistic, so I would keep it simple and just look for each patter to be ignored:

findstr /v /r /c:"window.x=" /c:"window.y=" /c:"window.width=" /c:"window.height=" in.txt > out.txt

Open in new window


~bp
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40617541
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

0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 40617550
@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
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 40631152
Thanks, glad that was useful.

~bp
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question