?
Solved

Windows Script to search a files and delete value

Posted on 2015-02-18
8
Medium Priority
?
92 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 56

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 56

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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 25

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 56

Accepted Solution

by:
Bill Prew earned 2000 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 25

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 56

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 56

Expert Comment

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

~bp
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…

752 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