Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Update specific text in file from shell script

I am trying to update specific entries in a document from a user prompt in a shell script. The user should be promoted to enter their domain name and then the script should update the ‘yourdomain.com’ section on 3 different lines. The name of the text file is .env

IMAGE_REPO=tacticalrmm/
VERSION=latest
TRMM_USER=username
TRMM_PASS=password

APP_HOST=rmm.yourdomain.com
API_HOST=api.yourdomain.com
MESH_HOST=mesh.yourdomain.com

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

it is very easy, you can use sed to update specific entries in the .env file from a shell script

#!/bin/bash

read -p "Enter your domain name: " domain

sed -i "s/yourdomain.com/$domain/g" .env

echo "Updated values:"
cat .env

I’ve helped you this time, but remember that no one here is writing code for anyone, we’re here to solve your problems in your code and help you!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading