How to edit a line in a file using a batch file??????

Basically i want to edit one line in a properties file, using a batch file, Here is what it says

#Minecraft server properties
#Tue Feb 22 15:58:36 PST 2011
level-name=world2
hellworld=false
spawn-monsters=true
online-mode=false
spawn-animals=true
max-players=5
server-ip=5.196.238.77
pvp=true
server-port=25565
white-list=false

The IP address needs to be changed, i have a hamachi server and a server for home but i need to change this to my ip address on my computer wich is 192.168.1.74. This needs to be changed back and forth so how can i make a batch that just runs and then done its been changed.

imac 21.5, Mac OS X (10.6.5), hi

Posted on Mar 31, 2011 12:27 PM

Reply
2 replies

Mar 31, 2011 1:17 PM in response to wiinick100

There are no .bat files in a Unix environment 🙂

#!/usr/bin/env bash
export NEW_IP=192.168.1.74
perl -ni -e '
s/d.d+.d+.d/$ENV{"NEW_IP"}/;
print;
' yourpropertiesfile

Make sure you change the file's protections so they are executable

chmod +x nameof_yourscript

There are other ways to do this, I just choose a perl script within a bash script. You could do it all with a bash script, you could use awk, you could use sed, you could use python, ruby, etc...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to edit a line in a file using a batch file??????

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.