5

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?

Jananath Banuka
  • 2,951
  • 8
  • 57
  • 105
  • https://stackoverflow.com/questions/5014632/how-can-i-parse-a-yaml-file-from-a-linux-shell-script – yussuf Jan 29 '21 at 07:38

1 Answers1

5

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
Dee
  • 7,455
  • 6
  • 36
  • 70