Last active
May 7, 2022 14:23
-
-
Save KR1470R/5dab2893487c2f74474b7619fb6fac74 to your computer and use it in GitHub Desktop.
This script actually used for massive changing name and url of ~/.local/share/okular/docdata/*.pdf.xml files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
echo ${1:?Destination path is not specified} | |
export filenames=$(ls -1 $1) | |
export IFS=$'\n' | |
function main () { | |
export previus_href | |
export previus_input | |
for filename in $filenames; do | |
export filepath=$1'/'$filename | |
export href=$(cat $filepath | grep '<documentInfo' | cut -d '"' -f 2) | |
# path_to_file -> inner_href_the_file | |
echo "Current line:>${filename} -> ${href}" | |
if [[ "$href" == "$previus_href" ]]; then | |
printf "Automatic changing for: %s"$href | |
echo | |
sed -i "s,$previus_href,$previus_input,g" $filepath | |
else | |
if [ $(echo $href | grep -o "DELETED|" | wc -m) -ne 0 ]; then | |
echo "Marked as deleted. Passing..." | |
continue | |
elif [ $(echo $href | egrep "Education" | wc -m) -ge 3 ]; then | |
echo "Have changed. Passing..." | |
continue | |
else | |
printf "Change for: %s"$href | |
echo | |
printf ">" | |
read new_href | |
if [ $(echo $new_href | wc -m) -eq 1 ]; then | |
echo "Passed by a user..." | |
continue | |
elif [[ $new_href == "del" ]]; then | |
echo "Marking as DELETED..." | |
export replace_string="DELETED|"$href | |
sed -i "s,$href,$replace_string,g" $filepath | |
else | |
echo "Replacing specified href..." | |
sed -i "s,$href,$new_href,g" $filepath | |
fi | |
export previus_input=$new_href | |
fi | |
fi | |
export previus_href=$href | |
echo "================================================================" | |
done | |
} | |
main $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment