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.

Revisions

  1. wsilva created this gist Jun 24, 2021.
    27 changes: 27 additions & 0 deletions k8s-yaml-splitter.sh
    Original 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