1 changed files with 35 additions and 0 deletions
@ -0,0 +1,35 @@ |
|||
#!/bin/bash |
|||
|
|||
# Add terzina tags to each canto.xml file in a directory |
|||
# Also add canto number attribute. |
|||
|
|||
echo -e "\nAdding terzina tags and numbers." |
|||
|
|||
for file in *; |
|||
do |
|||
if [[ "$file" != 'tercet-tags.sh' ]]; then # exclude this script |
|||
if [[ "$file" != sed* ]]; then # exclude sed file made later |
|||
echo -e "Modifying $file" |
|||
# Every third line (mod 3) add a closing tag, newline, and opening tag. |
|||
# TODO |
|||
# How many tabs to add? |
|||
awk -i inplace '{print}; NR % 3 == 0 {print "\t\t</tercet>\n\t\t<tercet num=~NUM~>"}' "$file" |
|||
# Add an opening tag at the beginning and a closing tag at the end because the above awk doesn't. |
|||
sed -i '1s/^/\t\t<tercet num="1">\n/' "$file" |
|||
echo -e "\t\t</terzina>" >> "$file" |
|||
# Add the canto number attribute (at most 160/3 ~ 54 terzine) |
|||
for i in $(seq 1 54); |
|||
do |
|||
# Substitute in the actual number with sed. I couldn't figure out |
|||
# how to include the $i variable with the surrounding attribute |
|||
# quotes in the awk statement, so I just used sed here separately. |
|||
|
|||
# We start at i=2 because the awk command above |
|||
# doesn't add a terzina tag to the first terzina. |
|||
TERZ_NUM=$((i + 1)) |
|||
# Replace only first occurence of ~NUM~. |
|||
sed -i -e "0,/~NUM~/ s/~NUM~/\"$TERZ_NUM\"/" "$file" |
|||
done |
|||
fi |
|||
fi |
|||
done |
|||
Loading…
Reference in new issue