LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-19-2020, 06:49 AM   #1
gurukr040
LQ Newbie
 
Registered: Jun 2020
Posts: 1

Rep: Reputation: Disabled
replacing contents based on output


Hello.
I execute 'k get bd' and get below output.Also another file in my repo 'file.yaml' which has entries like below.
Need to read the output of 2nd column and replace entries in the file.yaml at "testing.in/hostname" and 1st column with "blockDeviceName".
The required file that should be after modification is "file2.yaml".
Any suggestions or help.It should read each value from the command output and edit the same in file.yaml.


NAME NODE
blockdevice-0c008888888888888433c50 drac-1
blockdevice-999999fc000c90d8ae958b4 drac-2
blockdevice-e2979399960ad81255413cc drac-3
blockdevice-78787878787878f6a4842cc drac-4


file.yaml:

- nodeSelector:
testing.in/hostname: "machine1"
RaidMember:
- blockDevice:
- blockDeviceName: "blockdevice-0fggh44445555556"
matrixConfig:
dataRaidGroupType: "raid"
- nodeSelector:
testing.in/hostname: "machine2"
RaidMember:
- blockDevice:
- blockDeviceName: "blockdevice-9090908124667899"
matrixConfig:
dataRaidGroupType: "raid"


file2.yaml

- nodeSelector:
testing.in/hostname: "drac-1"
RaidMember:
- blockDevices:
- blockDeviceName: "blockdevice-0c008888888888888433c50"
matrixConfig:
dataRaidGroupType: "raid"
- nodeSelector:
testing.in/hostname: "drac-2"
RaidMember:
- blockDevices:
- blockDeviceName: "blockdevice-999999fc000c90d8ae958b4"
matrixConfig:
dataRaidGroupType: "raid"
 
Old 06-19-2020, 07:01 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,688

Rep: Reputation: Disabled
I'll just quote myself:
Quote:
Originally Posted by shruggy View Post
A good tool to edit YAML from shell scripts is yq.
You also may play around with kubectl options. I think it can handle YAML by itself.

Last edited by shruggy; 06-19-2020 at 07:20 AM.
 
Old 06-19-2020, 09:21 AM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by gurukr040 View Post
file2.yaml

- nodeSelector:
testing.in/hostname: "drac-1"
RaidMember:
- blockDevices:
- blockDeviceName: "blockdevice-0c008888888888888433c50"
matrixConfig:
dataRaidGroupType: "raid"
- nodeSelector:
testing.in/hostname: "drac-2"
RaidMember:
- blockDevices:
- blockDeviceName: "blockdevice-999999fc000c90d8ae958b4"
matrixConfig:
dataRaidGroupType: "raid"
Do you understand why code should be formatted as code? It's impossible to see the structure of the YAML file when you don't format it. See my signature if you need instructions.
 
  


Reply

Tags
kubernetes, yaml



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Is there a command line way to print out all of the contents and sub directories contents of a directory? wh33t Linux - Software 5 06-07-2016 01:45 PM
sed -- replacing a string in a file with the contents of another file? CGP314 Linux - Newbie 10 06-17-2010 04:29 PM
pci based usb hc based on necd72010xf1 and pinnacle pctv card bt878 based ashwani_gupt Linux - Hardware 0 12-17-2009 08:34 AM
list contents of directory without listing contents baddah Linux - Newbie 2 06-12-2006 04:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration