【发布时间】:2017-06-11 07:08:44
【问题描述】:
我有大约 600 本 PDF 格式的书籍,其中文件名的格式为:
AuthorForename AuthorSurname - Title (Date).pdf
例如:
Foo Z. Bar - 为白痴编写脚本(2017 年)
Bar Foo - PDF 的乐趣 (2016)
不幸的是,几乎所有这些元数据都丢失了,所以当我将它们导入 Calibre 时,Author 字段是空白的。
我正在尝试编写一个脚本,它将获取出现在“-”之前的所有内容,删除尾随空格,然后使用 exiftool 将其作为作者添加到 PDF 元数据中。
到目前为止,我有以下内容:
for i in "*.pdf";
do exiftool -author=$(echo $i | sed 's/-.*//' | sed 's/[ \t]*$//') "$i";
done
但是,当尝试运行它时,会返回以下内容:
Error: File not found - Z.
Error: File not found - Bar
Error: File not found - *.pdf
0 image files updated
3 files weren't updated due to errors
-author= 短语在这里被破坏了怎么办?请有人能启发我吗?
【问题讨论】:
-
当您看到 shell 没有扩展
*字符时,这表明您要删除*.pdf周围的 dbl 引号。此外,下面的答案看起来非常方便。一个很好的第一个 Q,请继续发帖,但请阅读stackoverflow.com/help/how-to-ask、stackoverflow.com/help/dont-ask、stackoverflow.com/help/mcve 并在此处发布更多 Q 之前采取tour。祝你好运。 -
谢谢,我会确保这样做