Skip to main content

3 posts tagged with "sed"

View All Tags

Compare environment files in the Linux console

ยท 4 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Compare environment files in the Linux console

This is a very common source of problems using .env files: you've two or more different .env file like .env and .env.example.

You're a programmer and coding a new amazing feature. You're adding one or more new environment variables to your local .env file and everything is working fine on your computer.

Boum! Your feature is buggy.

A colleague copy the source code from a versioning system like Github/GitLab or, second scenario, someone will deploy the feature on a server and your feature is broken.

Why? Because the variable(s) you've added have been added in your local .env file, on your computer only.

As you know, you have to create the variables in the .env.example file too but let's be honest, nobody thinks about it.

Batch edit of environment file

ยท 4 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Batch edit of environment file

When deploying a project on servers, we need to pay particular attention to the .env file. This file is crucial and will determine whether our application works properly (or crashes).

The normal way of doing things is to run a git clone command to get the latest version of the application from a repository (branch test for a test server, dev for an acceptance server, main for a production server).

Once cloned, the next command will be to create the .env file and it's done using cp .env.example .env.

And that's where the obligation to be meticulous begins.

Search and replace (or add) using sed

ยท 3 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Search and replace (or add) using sed

Today, I was facing (once more) with the following need: I need to update a setting in a text file but if the variable is not yet present, I need to add it.

So, in short, I need to make a search and replace or insert new line.

Using sed it's quite easy to automate the search & replace but how to append?