Skip to content

Instantly share code, notes, and snippets.

@wsilva
Created June 24, 2021 14:52
Show Gist options
  • Save wsilva/c45178e23dc48dcab46c8c71be223ee3 to your computer and use it in GitHub Desktop.
Save wsilva/c45178e23dc48dcab46c8c71be223ee3 to your computer and use it in GitHub Desktop.
k8s-yaml-splitter.sh
#!/bin/bash
# usage: ./k8s-yaml-splitter file.yaml
file=$1
output=yabadabadoo_
count=$(cat ${file} | wc -l)
count=$((count + 1))
lines=$(grep -n -e '---' ${file} | awk -F: '{ print $1 }')
lines="${lines} ${count}"
start=$(echo ${lines} | awk '{ print $1 }')
lines=$(echo ${lines} | sed 's/^[0-9]*//')
for n in ${lines}
do
end=$((n - 1))
sed -n "${start},${end}p" ${file} > "${output}${start}-${end}.yaml"
start=$n
done
count=0
for i in $(ls | grep ${output})
do
kind=$(grep '^kind' $i | cut -d ' ' -f 2 )
mv "$i" "$count-$kind.yaml"
(( count++ ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment