Solved

Windows Script to search a files and delete value

Posted on 2015-02-18
8
85 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
  • 5
  • 2
8 Comments
 
LVL 52

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 52

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
 
LVL 23

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 52

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 23

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 52

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 52

Expert Comment

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

~bp
0

Featured Post

Are end users causing IT problems again?

You’ve taken the time to design and update all your end user’s email signatures, only to find out they’re messing up the HTML, changing the font and ruining the imagery. What can you do to prevent this? Find out how you can save your signatures from end users today.

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now