How to read a yaml or env file using bash

Jananath Banuka

I have a .yml file and it has content like below:

env_values:
 stage: build
 before_script: some-value 

So I need to read and get the values for stage and before_script, so they will have build and some-value respectively.

Is there a good easy workaround in bash scripting to read this file and get the values?

datdinhquoc

Assume your .yml file is t.yml, this Bash script gets the 2 values you need:

arr=($(cat t.yml | grep "stage:"))
stage=${arr[1]}
echo $stage

arr=($(cat t.yml | grep "before_script:"))
before_script=${arr[1]}
echo $before_script

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to read from YAML file in java?

From Java

npm scripts: read .env file

From Dev

How to read a single file in Heroku via bash

From Dev

How to update yaml file using python

From Dev

How to read in csv file to array in bash script

From Dev

How to read from file *and* stdin in bash

From Dev

How to read a single column CSV file in bash?

From Dev

How to read a YAML file

From Dev

How to read a text file with php or bash and sort it?

From Dev

Bash script - how to read file line by line while using getopts

From Dev

How to update yaml file using python?

From Dev

Read YAML file as list

From Dev

Ruby - Not able to read yaml file

From Dev

Read Elements from file using bash script

From Dev

How to read while reading from a file in bash

From Dev

How to read a single column CSV file in bash?

From Dev

How to read yaml properties using javascript

From Dev

How to read variables from a php file in bash

From Dev

Read template file and replace variable using Bash

From Dev

How to read coordinates from text file in bash?

From Dev

How to encrypt a file using Bash?

From Dev

How to read a text file with php or bash and sort it?

From Dev

How to update yaml file using python?

From Dev

Using read command to read file by line in Bash doesn't work

From Dev

How to read a matrix from a file and assign to 2 dimensional array(Matrix) declared in bash script using awk

From Dev

Simple BASH - how to read file line by line

From Dev

How to read file in bash using a fixed number of character?

From Dev

How to read file line by line in Bash script?

From Dev

How do I read a file into a matrix in bash?

Related Related

HotTag

Archive