windows batch script that delets lines

The below script adds 5 lines to a file called config.cfg.  

I need it to delete the 5 lines before it adds them.  Or at least a seperate script that just deletes the 5 lines.  I tried using "DEL" instead of echo but that did not work.  

working example that adds 5 lines below...
for /F "tokens=*" %%F in ('dir c:\progra~1\bquest\config.cfg /s/b') do (
(echo seta com_hunkmegs "192"
 echo seta com_soundmegs "32"
 echo seta com_zonemegs "32"
 echo seta cl_punkbuster "1"
 echo seta sv_punkbuster "1"
) >> "%%F")

I need this in batch, sorry I can't find windows batch zone when I need it.  
icecom4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Didn't work well with just appending those lines to the file? Ok, so we filter and append:
for /F "tokens=*" %%F in ('dir c:\progra~1\bquest\config.cfg /s/b') do (
   findstr /v /i /c:"seta com_hunkmegs" /c:"seta com_soundmegs" /c:"seta com_zonemegs" /c:"seta cl_punkbuster" /c:"seta sv_punkbuster" "%%F" > "%%F.tmp"
  (echo seta com_hunkmegs "192"
   echo seta com_soundmegs "32"
   echo seta com_zonemegs "32"
   echo seta cl_punkbuster "1"
   echo seta sv_punkbuster "1"
  ) >> "%%F.tmp"
  del "%%F"
  ren "%%F.tmp" "%%F"
)

Open in new window

0
icecom4Author Commented:
Ok, I will try.  By the way thanks for moving me to zone...but why can't I find Windows batch scripting?  Even if I type Windows batch scripting in the zone search, I only get it once in a while.  Is there a limit or somwthing on how many questions I can ask per zone???

0
Steve KnightIT ConsultancyCommented:
The only easy(ish) way you are going to do that without an external util or looping through the file a line at a time is to create a temporary file and adjust that, e.g.

findstr /l /v "com_hunkmegs com_soundmegs com_zonemegs cl_punkbuster sv_punkbuster" "%%~F" > "%temp%\config.cfg"
(echo seta com_hunkmegs "192"
 echo seta com_soundmegs "32"
 echo seta com_zonemegs "32"
 echo seta cl_punkbuster "1"
 echo seta sv_punkbuster "1"
) >> "%temp%\config.cfg"
copy "%temp%\config.cfg" "%%~F"
DEL /q "%temp%\config.cfg"

i.e. check using findstr for all those strings and exclude the lines with those on into file in temp drive
add the new entries to the end of the file
copy it back to original location and delete the temp file

With the code you have the for / dir seems a little redundant but I presume you have this as part of one of your bigger batches

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hey MSSPs! What's your total cost of ownership?

WEBINAR: Managed security service providers often deploy & manage products from a variety of solution vendors. But is this really the best approach when it comes to saving time AND money? Join us on Aug. 15th to learn how you can improve your total cost of ownership today!

Steve KnightIT ConsultancyCommented:
Hmm, get the alert, type up a solution and someone is already there :-)

Steve
0
icecom4Author Commented:
it only renamed the file to config.cfg.tmp for some reason
0
icecom4Author Commented:
ok above comment was for qelmo, let me try dragon
0
Steve KnightIT ConsultancyCommented:
0
icecom4Author Commented:
Thanks, this works
0
Steve KnightIT ConsultancyCommented:
Thanks.  Still can't see why Qlemo's doesn't.... unless it is down to " " being in the %%F results?

Anyway glad it worked!

Steve
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.