[Solved] Modify yaml file in bash without any external dependency

Pranjal Doshi Asks: Modify yaml file in bash without any external dependency
I’ve multiple configurations in YAML file and I need to change some paramaters using a Bash script. Is it possible? I want to avoid using any external program.

My YAML Looks like

Code:
%YAML 1.2
---
name: mic
components:
- name: Mic
  parameters:
    period_count: 4
    alsa_device_name: "pulse"

---
name: speaker
components:
- name: Speaker
  parameters:
    period_duration_ms: 20
    period_count: 4
    alsa_device_name: "pulse"

I want it to behave like if I provide --mic logitec --speaker hk34 then it should modify alsa_device_name for both mic and speaker in my config to

Code:
%YAML 1.2
---
name: mic
components:
- name: Mic
  parameters:
    period_count: 4
    alsa_device_name: "logitec"

---
name: speaker
components:
- name: Speaker
  parameters:
    period_duration_ms: 20
    period_count: 4
    alsa_device_name: "hk34"

Is it possible to do it using only Bash, and if so, how? For now I am using a Python script but this adds an extra dependency of having python3, which is something I want to avoid.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.