Reputation: 1999
I'd like to generate some .env.example
files for a dozen of projects.
In order to be smart and avoid tedious copy/pasting I thought about using the grep
command.
How can I get from :
➜ app-service git:(chore/adding-env-example) ✗ c;grep -r "process\.env\." --exclude-d
ir=node_modules
./src/config/config_prod.js: level: process.env.LOG_LEVEL || 'error'
./src/config/config_prod.js: bypassToken: process.env.BYPASS_TOKEN || null
./src/config/config.js: port: process.env.APP_PORT || 3000,
./src/config/config.js: frontUrl: process.env.FRONT_URL,
./src/config/config.js: launchAppTopic: process.env.AWS_SNS_LAUNCH_APP_ARN
...
to
LOG_LEVEL=
BYPASS_TOKEN=
APP_PORT=
FRONT_URL=
AWS_SNS_LAUNCH_APP_ARN=
?
Upvotes: 1
Views: 3627
Reputation: 4890
grep -oP "(?<=\.)[[:upper:]_]*(?=[ ,]*)"
LOG_LEVEL
BYPASS_TOKEN
APP_PORT
FRONT_URL
AWS_SNS_LAUNCH_APP_ARN
=
sed -r -n 's|^.*\.([[:upper:]_]+).*$|\1=|p'
LOG_LEVEL=
BYPASS_TOKEN=
APP_PORT=
FRONT_URL=
AWS_SNS_LAUNCH_APP_ARN=
Upvotes: 1
Reputation: 93715
If you want to find all occurrences of an uppercase letter followed by uppercase letters and/or underscores, and then an =
, and only if it is a word in itself:
grep -o -P '\b[A-Z][A-Z_]*='
Upvotes: 0