Skip to content

Instantly share code, notes, and snippets.

@yglodt
Created February 7, 2019 07:48
Show Gist options
  • Save yglodt/28de98354e1f2e45ede9bb5939ea0234 to your computer and use it in GitHub Desktop.
Save yglodt/28de98354e1f2e45ede9bb5939ea0234 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 54321_xxxxxx_yyyyy.pdf
# 54321_xxxxxx_yyyyy.pdf
# 54321_xxxxxx_yyyyy.pdf
# will become 54321.pdf
# 54322_xxxxxx_yyyyy.pdf
# 54322_xxxxxx_yyyyy.pdf
# will become 54322.pdf
cd /mnt/c/TEMP/pdfs
list="";
for file in *pdf; do
if [ -f "$file" ]; then
#echo "$file"
num="${file:0:5}"
list="$list $num"
fi
done
#echo $list
uniques=$(echo $list | tr ' ' '\n' | sort -nu)
#echo $uniques
for uni in $uniques; do
echo "Creating $uni ..."
pdfunite $(echo "$uni"_*) "merged/$uni.pdf"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment