Solved

Windows Script to search a files and delete value

Posted on 2015-02-18
8
83 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 51

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 51

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 51

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 51

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 51

Expert Comment

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

~bp
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
nmap scanner? 7 78
Command to modify Registry entry 5 82
OUtlook missing email alert 9 18
firefox deployment by sccm 1 20
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...
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

705 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

17 Experts available now in Live!

Get 1:1 Help Now