Skip to content

Instantly share code, notes, and snippets.

@hungryzi
Last active September 24, 2017 00:53
Show Gist options
  • Save hungryzi/22332c9e91fd23ea5a30b6d0654321d4 to your computer and use it in GitHub Desktop.
Save hungryzi/22332c9e91fd23ea5a30b6d0654321d4 to your computer and use it in GitHub Desktop.
Removing unneeded pages from F941
#!/bin/bash
INPUT=~/Downloads/f941
DONE=$INPUT/done
OUTPUT=$INPUT/output
mkdir -p $DONE
mkdir -p $OUTPUT
PDFS=$INPUT/*.pdf
FILES=($INPUT/*.pdf)
COUNT=${#FILES[@]}
NTH=0
function process_pdf {
pdftk "$1" cat ${@:3} output "$OUTPUT/$2"
if [ $? == 0 ]
then
mv "$1" "$DONE"
else
echo "!!!!!!!!!! ERRORED"
fi
}
for f in $PDFS
do
FILENAME=$(basename "$f")
NUMBER_OF_PAGES=$(pdfinfo "$f" | grep Pages | awk '{print $2}')
if [ $NUMBER_OF_PAGES == 4 ] || [ $NUMBER_OF_PAGES == 5 ]
then
process_pdf "$f" "$FILENAME" 1 2
elif [ $NUMBER_OF_PAGES == 6 ]
then
process_pdf "$f" "$FILENAME" 1 2 5
else
echo "!!!!!!!!!! SKIPPED: File $f has weird number of pages! ($NUMBER_OF_PAGES)"
fi
((++NTH))
echo "processed $NTH/$COUNT files: $FILENAME"
done
echo "DONE! Check your directory for any skipped files!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment