#!/bin/bash # This script adds top-level tags to your XML files. # - XML header # - and tags with attributes echo -e "\nAdding top-level tags." for file in *; do if [[ "$file" != 'top-level-tags.sh' ]]; then CANTO_NUM="$(echo "'$file'" | tr -d -c 0-9)" # get canto number if [[ "$file" == inferno* ]]; then COMM_NUM="$CANTO_NUM" # same as inferno canto number elif [[ "$file" == purgatorio* ]]; then COMM_NUM="$((CANTO_NUM + 34))" # add 34 if in purgatory else COMM_NUM="$((CANTO_NUM + 67))" # add 68 if in paradise fi # Add tags to first line of file sed -i '1s/^/\n\n\n\t\n/' "$file" # Replace canto number and comedy number sed -i "s/~CANTO_NUM~/\"$CANTO_NUM\"/" "$file" sed -i "s/~COMM_NUM~/\"$COMM_NUM\"/" "$file" # Add tags to end of file echo -e "\t" >> "$file" echo -e "" >> "$file" # Add a `.xml` extension mv "$file" "$file.xml" fi done