Skip to content

Instantly share code, notes, and snippets.

@amio
Last active March 14, 2020 13:52
Show Gist options
  • Save amio/a4f810265ffa0b8d2a38c54227e83289 to your computer and use it in GitHub Desktop.
Save amio/a4f810265ffa0b8d2a38c54227e83289 to your computer and use it in GitHub Desktop.
Remove ''www.it-ebooks.info" from pdf.
#!/bin/bash
source_dir=$1;
find "$1" -type f -name "*.pdf" -print0|while read -d $'\0' file;
do
if [ `strings "$file"|grep -c "www.it-ebooks.info"` -gt 0 ];
then
echo "$file";
cp "$file" /tmp/1.pdf;
script=$(cat <<'EOF'
use strict;
use warnings;
open(my $in, '<', '/tmp/1.pdf')
or die "Cannot open input.txt: $!";
open(my $out, '>', '/tmp/2.pdf')
or die "Cannot open output.txt: $!";
while (<$in>) {
print $out $_ unless /www.it-ebooks.info/;
}
close($in);
close($out);
EOF
)
/usr/bin/perl -e "$script"
mv -v /tmp/2.pdf "$file";
rm /tmp/1.pdf
fi;
done
# Usage:
# chmod +x rm-ite.sh
# ./rm-ite.sh ~/pdf-dir
@Alexound
Copy link

...just great.

@WillingAC
Copy link

Thank you for your sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment