<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.iwillfearnoevil.com/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Create-yml-from-bash-include</id>
	<title>Create-yml-from-bash-include - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.iwillfearnoevil.com/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Create-yml-from-bash-include"/>
	<link rel="alternate" type="text/html" href="https://wiki.iwillfearnoevil.com/mediawiki/index.php?title=Create-yml-from-bash-include&amp;action=history"/>
	<updated>2026-05-08T15:47:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.2</generator>
	<entry>
		<id>https://wiki.iwillfearnoevil.com/mediawiki/index.php?title=Create-yml-from-bash-include&amp;diff=20&amp;oldid=prev</id>
		<title>Chubbard: Created page with &quot;[https://stackoverflow.com/questions/41598377/create-bash-script-to-create-yaml-files-from-existing-linux-etc-hosts-files|Source site]  This is going to be VERY fragile, but d...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.iwillfearnoevil.com/mediawiki/index.php?title=Create-yml-from-bash-include&amp;diff=20&amp;oldid=prev"/>
		<updated>2021-10-15T19:55:45Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;[https://stackoverflow.com/questions/41598377/create-bash-script-to-create-yaml-files-from-existing-linux-etc-hosts-files|Source site]  This is going to be VERY fragile, but d...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[https://stackoverflow.com/questions/41598377/create-bash-script-to-create-yaml-files-from-existing-linux-etc-hosts-files|Source site]&lt;br /&gt;
&lt;br /&gt;
This is going to be VERY fragile, but does work for simple yaml.  Overall it is last resort, but can get you out of a jam.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  printf 'host_entries:\n'&lt;br /&gt;
  while read -r -a line; do&lt;br /&gt;
    [[ ${line[0]} ]] || continue             # skip blank lines&lt;br /&gt;
    [[ ${line[0]} = &amp;quot;#&amp;quot;* ]] &amp;amp;&amp;amp; continue      # skip comments&lt;br /&gt;
    [[ ${line[0]} = 127.0.0.1 ]] &amp;amp;&amp;amp; continue # skip localhost&lt;br /&gt;
&lt;br /&gt;
    set -- &amp;quot;${line[@]}&amp;quot; # assign words read from line to current argument list&lt;br /&gt;
    ip=$1; shift        # assign first word from line to ip&lt;br /&gt;
    for name; do        # iterate over other words, treating them as names&lt;br /&gt;
      printf &amp;quot;  %s:\n    ip: '%s'\n&amp;quot; &amp;quot;$name&amp;quot; &amp;quot;$ip&amp;quot;&lt;br /&gt;
    done&lt;br /&gt;
  done&lt;br /&gt;
} &amp;lt;/etc/hosts &amp;gt;yourfile.yaml&lt;br /&gt;
&lt;br /&gt;
This is WRONG but works for this simple case.  Creating a YML file from a vars file should be less problematic however since it is key=value&lt;br /&gt;
&lt;br /&gt;
This will allow creating a YML file with bash substitutions.&lt;br /&gt;
example is for bosh!!&lt;br /&gt;
https://www.starkandwayne.com/blog/bashing-your-yaml/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
[[Category:bash]]&lt;/div&gt;</summary>
		<author><name>Chubbard</name></author>
	</entry>
</feed>