Created
          June 24, 2021 14:52 
        
      - 
      
- 
        Save wsilva/c45178e23dc48dcab46c8c71be223ee3 to your computer and use it in GitHub Desktop. 
Revisions
- 
        wsilva created this gist Jun 24, 2021 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/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