Created
June 24, 2021 14:52
-
-
Save wsilva/c45178e23dc48dcab46c8c71be223ee3 to your computer and use it in GitHub Desktop.
k8s-yaml-splitter.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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