Storage for XML files used to represent Dante's *Divine Comedy*.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

31 lines
1021 B

#!/bin/bash
# This script adds top-level tags to your XML files.
# - XML header
# - <canto> and <terzine> 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/^/<?xml version="1.0" encoding="UTF-8"?>\n\n<canto num=~CANTO_NUM~ num_comm=~COMM_NUM~>\n\t<terzine>\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</terzine>" >> "$file"
echo -e "</canto>" >> "$file"
# Add a `.xml` extension
mv "$file" "$file.xml"
fi
done