Jump to content

Writing to text file with batch?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Flaringo

Flaringo

    Newbie

  • Members
  • Pip
  • 1 posts
I'm trying to write a line to a text file using a batch file. My problem is that I can only make it write to the end of the file.

I have this file with several lines of text, for example a config file for a game:

playerhealth = 100

playerammo  = 50

playermodel = jack

playername = Lars

crosshair = small

crosshaircolor = red

I want to change the playername-value to something else. How would I go about doing this? I'

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I think you'll need something more powerful than a simple batch file. Tools like sed and awk were created for this type of change.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
JenniC

JenniC

    Newbie

  • Members
  • Pip
  • 6 posts
If the file is game.cfg and the replace value is "player2" (after "playername = "), the following command line in biterscripting will do the job.

var str s ; cat "game.cfg" > $s ; sal -c -r "playername = &\n" "playername = player2\n" $s ; echo $s > "game.cfg"

Use correct file path in place game.cfg. Use correct value of "player2". Download biterscripting from biterscripting.com . Enter the above command line into biterscripting, or save it as script and execute the script.

Jenni

#4
hodge-podge

hodge-podge

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
Are you trying to write a game in batch? I guess it is possible, but I would suggest trying a more powerful language.