Browse Source

add TEI tags and header

main
lhess2021 4 years ago
parent
commit
f4ddc7c4cd
  1. 33
      shell-scripts.d/top-level-tags.sh

33
shell-scripts.d/top-level-tags.sh

@ -2,6 +2,7 @@
# This script adds top-level tags to your XML files. # This script adds top-level tags to your XML files.
# - XML header # - XML header
# - TEI header
# - <canto> and <terzine> tags with attributes # - <canto> and <terzine> tags with attributes
echo -e "\nAdding top-level tags." echo -e "\nAdding top-level tags."
@ -11,20 +12,38 @@ do
if [[ "$file" != 'top-level-tags.sh' ]]; then if [[ "$file" != 'top-level-tags.sh' ]]; then
CANTO_NUM="$(echo "'$file'" | tr -d -c 0-9)" # get canto number CANTO_NUM="$(echo "'$file'" | tr -d -c 0-9)" # get canto number
if [[ "$file" == inferno* ]]; then if [[ "$file" == inferno* ]]; then
CANTICLE="Inferno"
COMM_NUM="$CANTO_NUM" # same as inferno canto number COMM_NUM="$CANTO_NUM" # same as inferno canto number
elif [[ "$file" == purgatorio* ]]; then elif [[ "$file" == purgatorio* ]]; then
CANTICLE="Purgatorio"
COMM_NUM="$((CANTO_NUM + 34))" # add 34 if in purgatory COMM_NUM="$((CANTO_NUM + 34))" # add 34 if in purgatory
else elif [[ "$file" == paradiso* ]]; then
CANTICLE="Paradiso"
COMM_NUM="$((CANTO_NUM + 67))" # add 68 if in paradise COMM_NUM="$((CANTO_NUM + 67))" # add 68 if in paradise
else
echo -e "\nWhat file is this? $file"
fi fi
# Add tags to first line of file # 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" sed -i -e '1s/^/<?xml version="1.0" encoding="UTF-8"?>\
# Replace canto number and comedy number \n<TEI xmlns="http:\/\/www.tei-c.org\/ns\/1.0">\
sed -i "s/~CANTO_NUM~/\"$CANTO_NUM\"/" "$file" \t<teiHeader>\
sed -i "s/~COMM_NUM~/\"$COMM_NUM\"/" "$file" \t\t<fileDesc>\
\t\t\t<titleStmt>Canto ~TITLE_CANTO_NUM~ of ~CANTICLE~<\/titleStmt>\
\t\t<\/fileDesc>\
\t<\/teiHeader>\
\t<text>\
\t\t<canto num=~CANTO_NUM~ num_comm=~COMM_NUM~>\
\t\t\t<tercets>\n/' "$file"
# Replace canto number, comedy number, and canticle
sed -i -e "s/~TITLE_CANTO_NUM~/$CANTO_NUM/" "$file"
sed -i -e "s/~CANTO_NUM~/\"$CANTO_NUM\"/" "$file"
sed -i -e "s/~COMM_NUM~/\"$COMM_NUM\"/" "$file"
sed -i -e "s/~CANTICLE~/$CANTICLE/" "$file"
# Add tags to end of file # Add tags to end of file
echo -e "\t</terzine>" >> "$file" echo -e "\t\t\t</tercets>" >> "$file"
echo -e "</canto>" >> "$file" echo -e "\t\t</canto>" >> "$file"
echo -e "\t</text>" >> "$file"
echo -e "</TEI>" >> "$file"
# Add a `.xml` extension # Add a `.xml` extension
mv "$file" "$file.xml" mv "$file" "$file.xml"
fi fi

Loading…
Cancel
Save