bash脚本删除pdf元数据
问题描述:
我很新的bash脚本,我想从一个特定的目录及其子文件夹中删除PDF文件的所有元数据。 所以我把this script,并试图把它放在一个循环。bash脚本删除pdf元数据
for file in $(find . -iname '*.pdf')
do
pdftk $file dump_data | \
sed -e 's/\(InfoValue:\)\s.*/\1\ /g' | \
pdftk $1 update_info - output $file.tmp
exiftool -all:all= $file.tmp
exiftool -all:all $file.tmp
exiftool -extractEmbedded -all:all $file.tmp
qpdf --linearize $file.tmp $file
pdftk $file dump_data
exiftool $file
pdfinfo -meta $file
done
我得到一个错误,但我不明白为什么。
Error: No input files. Exiting.
Errors encountered. No output created.
无论如何,用这种方法去除不必要的信息还是有更好的方法?
电贺
答
这个版本的作品如预期,虽然它不是漂亮
find -name "* *" -type d | rename 's/ /_/g'
find -name "* *" -type f | rename 's/ /_/g'
# Removes whitespace from directories and files
for file in $(find . -iname '*.pdf')
do
pdftk $file dump_data | \
sed -e 's/\(InfoValue:\)\s.*/\1\ /g' | \
pdftk $file update_info - output $file-clean
exiftool -all:all= $file-clean
exiftool -all:all $file-clean
exiftool -extractEmbedded -all:all $file-clean
qpdf --linearize $file-clean $file-clean2
pdftk $file-clean2 dump_data
exiftool $file-clean2
pdfinfo -meta $file-clean2
rm -f $file $file-clean $file-clean_original $file_original
mv $file-clean2 $file
done
echo finished
这可能帮助:?如何调试bash脚本(http://unix.stackexchange.com/q/ 155551/74329) – Cyrus
同意。某种'set -x'来找出哪些线正在抱怨。那么你可以自己解决这个问题。 – Mort
谢谢,这是一个好tipp。一定是昨天失明了;-) –