Skip to content

Instantly share code, notes, and snippets.

@innermond
Created February 1, 2021 17:22
Show Gist options
  • Save innermond/73412a5824127b6adfc99d450b324deb to your computer and use it in GitHub Desktop.
Save innermond/73412a5824127b6adfc99d450b324deb to your computer and use it in GitHub Desktop.
calculate median ink coverage of all pages from a pdf FILE
#!/bin/bash
if [ -z $1 ]; then echo "introdu cale fisier"; exit 1; fi
covfile=${1%.*}.cov
# run this block in background
{
gs -o - -sDEVICE=inkcov "$1" > "$covfile"
sed -i -E '/^\S/d' "$covfile"
awk '{c+=$1; m+=$2; y+=$3; k+=$4; next} END{c=c/NR; m=m/NR; y=y/NR; k=k/NR; print "C="c " M="m " Y="y " K="k " T="c+m+y+k}' "$covfile"
if [ ! -z "$2" ]; then
rm "$covfile";
fi
} &
# wait here for completion of block above
pid=$! # Process Id of the previous running command
spin='—\|/'
i=0
while kill -0 $pid 2>/dev/null
do
i=$(( (i+1) %4 ))
printf "\r${spin:$i:1}"
sleep .1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment